/* ============================================================
   foreign-waters / TouchPoint Design System
   Dark-first, Tailwind-driven. This file provides base resets,
   custom component styles, and animations that Tailwind CDN
   cannot generate.
   ============================================================ */

/* --- Reset & Base --- */

*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto,
        "Helvetica Neue", Arial, sans-serif;
    background: #f8fafc;
    color: #1e293b;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow: hidden;
    transition: background-color 200ms ease, color 200ms ease;
}

html.dark body {
    background: #0f172a;
    color: #f1f5f9;
}

a {
    text-decoration: none;
}

/* --- TouchPoint Nav Links --- */

.tp-nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.625rem;
    color: #64748b;
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    border-radius: 0.5rem;
    transition: color 150ms ease, background 150ms ease;
    white-space: nowrap;
    margin-bottom: 1px;
}

.tp-nav-link:hover {
    color: #334155;
    background: rgba(0, 0, 0, 0.04);
}

.tp-nav-link.active {
    color: #059669;
    background: rgba(5, 150, 105, 0.08);
}

html.dark .tp-nav-link {
    color: #94a3b8;
}

html.dark .tp-nav-link:hover {
    color: #e2e8f0;
    background: rgba(255, 255, 255, 0.04);
}

html.dark .tp-nav-link.active {
    color: #34d399;
    background: rgba(52, 211, 153, 0.08);
}

/* --- Admin Nav Links --- */

.admin-nav-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.5rem 0.625rem;
    color: #64748b;
    font-size: 0.85rem;
    font-weight: 500;
    text-decoration: none;
    border-radius: 0.5rem;
    transition: color 150ms ease, background 150ms ease;
    white-space: nowrap;
    margin-bottom: 1px;
}

.admin-nav-link:hover {
    color: #334155;
    background: rgba(0, 0, 0, 0.04);
}

.admin-nav-link.active {
    color: #2563eb;
    background: rgba(37, 99, 235, 0.08);
}

html.dark .admin-nav-link {
    color: #94a3b8;
}

html.dark .admin-nav-link:hover {
    color: #e2e8f0;
    background: rgba(255, 255, 255, 0.04);
}

html.dark .admin-nav-link.active {
    color: #3b82f6;
    background: rgba(59, 130, 246, 0.08);
}

/* --- Animations --- */

@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}

@keyframes slideIn {
    from { opacity: 0; transform: translateY(-10px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

/* --- Spinner (border-3 is not a default Tailwind utility) --- */

.border-3 {
    border-width: 3px;
}

/* --- Scrollbar --- */

::-webkit-scrollbar {
    width: 6px;
    height: 6px;
}

::-webkit-scrollbar-track {
    background: transparent;
}

::-webkit-scrollbar-thumb {
    background: #cbd5e1;
    border-radius: 3px;
}

::-webkit-scrollbar-thumb:hover {
    background: #94a3b8;
}

html.dark ::-webkit-scrollbar-thumb {
    background: #334155;
}

html.dark ::-webkit-scrollbar-thumb:hover {
    background: #64748b;
}

/* --- Legacy Admin Page Styles (for /admin routes that still use old markup) --- */

.page-header {
    margin-bottom: 1.5rem;
}

.page-header h1 {
    font-size: 1.75rem;
    font-weight: 600;
    color: #1e293b;
    margin-bottom: 0.25rem;
}

html.dark .page-header h1 {
    color: #f1f5f9;
}

.text-muted {
    color: #64748b;
}

html.dark .text-muted {
    color: #94a3b8;
}

.card {
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 0.75rem;
    padding: 1.25rem;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
    transition: box-shadow 150ms ease, border-color 150ms ease;
}

.card:hover {
    box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
}

html.dark .card {
    background: #1e293b;
    border-color: #334155;
    box-shadow: 0 1px 2px rgba(0, 0, 0, 0.3);
}

html.dark .card:hover {
    box-shadow: 0 4px 6px rgba(0, 0, 0, 0.35);
}

.card-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
    padding-bottom: 0.75rem;
    border-bottom: 1px solid #e2e8f0;
}

html.dark .card-header {
    border-bottom-color: #334155;
}

.card-header h2,
.card-header h3 {
    margin: 0;
}

.card-body {
    color: #64748b;
}

html.dark .card-body {
    color: #94a3b8;
}

.card-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(320px, 1fr));
    gap: 1rem;
}

.badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.55rem;
    font-size: 0.7rem;
    font-weight: 600;
    border-radius: 9999px;
    background: #334155;
    color: #94a3b8;
    letter-spacing: 0.02em;
    white-space: nowrap;
}

.tier-badge {
    background: rgba(59, 130, 246, 0.15);
    color: #3b82f6;
    text-transform: lowercase;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    font-size: 0.875rem;
    font-weight: 500;
    line-height: 1.4;
    border: 1px solid transparent;
    border-radius: 0.5rem;
    cursor: pointer;
    transition: background 150ms ease, color 150ms ease, border-color 150ms ease;
    white-space: nowrap;
}

.btn:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.btn-primary {
    background: #3b82f6;
    color: #fff;
    border-color: #3b82f6;
}

.btn-primary:hover:not(:disabled) {
    background: #2563eb;
}

.btn-outline {
    background: transparent;
    color: #f1f5f9;
    border-color: #334155;
}

.btn-outline:hover:not(:disabled) {
    background: #334155;
}

.btn-sm {
    padding: 0.3rem 0.65rem;
    font-size: 0.8rem;
}

.input,
.textarea,
.select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    font-size: 0.875rem;
    color: #1e293b;
    background: #fff;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    outline: none;
    transition: border-color 150ms ease;
}

html.dark .input,
html.dark .textarea,
html.dark .select {
    color: #f1f5f9;
    background: #0f172a;
    border-color: #334155;
}

.input:focus,
.textarea:focus,
.select:focus {
    border-color: #3b82f6;
    box-shadow: 0 0 0 3px rgba(59, 130, 246, 0.15);
}

.textarea {
    min-height: 6rem;
    resize: vertical;
}

.spinner {
    display: inline-block;
    width: 1.5rem;
    height: 1.5rem;
    border: 2px solid #334155;
    border-top-color: #3b82f6;
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

/* Health card legacy */
.health-card {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 0.75rem;
    padding: 1.25rem;
    display: flex;
    flex-direction: column;
    gap: 0.75rem;
}

.health-card.ok { border-left: 3px solid #22c55e; }
.health-card.error { border-left: 3px solid #ef4444; }
.health-card.pending { border-left: 3px solid #f59e0b; }

.status-dot {
    display: inline-block;
    width: 0.5rem;
    height: 0.5rem;
    border-radius: 50%;
    flex-shrink: 0;
}

.status-ok { background: #22c55e; box-shadow: 0 0 6px #22c55e; }
.status-error { background: #ef4444; box-shadow: 0 0 6px #ef4444; }
.status-pending { background: #f59e0b; animation: pulse-glow 1.5s ease-in-out infinite; }

@keyframes pulse-glow {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.4; }
}

.result-box, pre {
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 0.5rem;
    padding: 0.75rem;
    overflow-x: auto;
    font-size: 0.85rem;
    margin-top: 0.75rem;
    color: #334155;
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
}

html.dark .result-box, html.dark pre {
    background: #0f172a;
    border-color: #334155;
    color: #e2e8f0;
}

code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Monaco, Consolas, monospace;
    font-size: 0.85em;
}

/* Chat legacy */
.chat-container,
.chat-card {
    display: flex;
    flex-direction: column;
    height: calc(100vh - 180px);
    max-height: 800px;
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 0.75rem;
    overflow: hidden;
}

.chat-message {
    max-width: 80%;
    padding: 0.75rem 1rem;
    border-radius: 0.75rem;
    font-size: 0.9rem;
    margin-bottom: 0.5rem;
}

.chat-user {
    align-self: flex-end;
    background: #3b82f6;
    color: #fff;
}

.chat-assistant {
    align-self: flex-start;
    background: #334155;
    color: #f1f5f9;
}

.chat-input-area {
    display: flex;
    gap: 0.5rem;
    padding: 0.75rem;
    border-top: 1px solid #334155;
    background: #0f172a;
}

.chat-input-area .textarea {
    flex: 1;
}

.chat-empty,
.chat-text { padding: 0.5rem; }

.chat-role {
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
    margin-bottom: 0.25rem;
    opacity: 0.7;
}

.cursor-blink {
    animation: blink 1s step-end infinite;
}

@keyframes blink {
    50% { opacity: 0; }
}

/* Notes/Push legacy */
.note-form,
.input-row,
.search-bar,
.button-row,
.notification-feed,
.note-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.input-row,
.search-bar,
.button-row {
    flex-direction: row;
    flex-wrap: wrap;
}

.note-card {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 0.75rem;
    padding: 0.75rem 1rem;
    cursor: pointer;
    transition: border-color 150ms ease;
}

.note-card:hover {
    border-color: #3b82f6;
}

.note-key {
    font-weight: 600;
    color: #f1f5f9;
    font-size: 0.9rem;
}

.note-content {
    color: #94a3b8;
    font-size: 0.85rem;
}

.note-meta {
    color: #64748b;
    font-size: 0.75rem;
}

.notification-item {
    background: #1e293b;
    border: 1px solid #334155;
    border-radius: 0.5rem;
    padding: 0.75rem;
}

.notification-title {
    font-weight: 600;
    color: #f1f5f9;
}

.notification-body {
    color: #94a3b8;
    font-size: 0.85rem;
}

.notification-time {
    font-size: 0.75rem;
}

/* Auth page legacy */
.auth-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.75rem;
    border-radius: 0.5rem;
    margin-bottom: 0.75rem;
    font-size: 0.9rem;
}

.auth-status-ok {
    background: rgba(34, 197, 94, 0.1);
    border: 1px solid rgba(34, 197, 94, 0.3);
    color: #22c55e;
}

.auth-status-none {
    background: rgba(239, 68, 68, 0.1);
    border: 1px solid rgba(239, 68, 68, 0.3);
    color: #ef4444;
}

.role-badges {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 1rem;
}

.role-demo {
    margin-top: 1rem;
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.role-content {
    padding: 0.75rem;
    border-radius: 0.5rem;
    font-size: 0.85rem;
}

.role-admin { background: rgba(239, 68, 68, 0.1); border: 1px solid rgba(239, 68, 68, 0.2); color: #fca5a5; }
.role-member { background: rgba(59, 130, 246, 0.1); border: 1px solid rgba(59, 130, 246, 0.2); color: #93c5fd; }
.role-viewer { background: rgba(34, 197, 94, 0.1); border: 1px solid rgba(34, 197, 94, 0.2); color: #86efac; }
.role-locked { background: rgba(100, 116, 139, 0.1); border: 1px solid rgba(100, 116, 139, 0.2); color: #94a3b8; }

.data-table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.data-table th {
    background: #334155;
    color: #f1f5f9;
    font-weight: 600;
    text-align: left;
    padding: 0.5rem 0.75rem;
}

.data-table td {
    padding: 0.5rem 0.75rem;
    border-bottom: 1px solid #1e293b;
    color: #94a3b8;
}

.health-status,
.health-latency,
.health-endpoint {
    font-size: 0.85rem;
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.health-grid {
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
}

.service-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 0.5rem;
}

.service-status {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    padding: 0.5rem;
    background: #0f172a;
    border-radius: 0.5rem;
}

.tier-list {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.tier-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    font-size: 0.85rem;
    color: #94a3b8;
}

.tier-item .badge {
    color: #fff;
    min-width: 3rem;
    justify-content: center;
}

.quick-links {
    display: flex;
    flex-direction: column;
    gap: 0.5rem;
}

.quick-link {
    display: block;
    padding: 0.5rem 0.75rem;
    font-size: 0.85rem;
    color: #3b82f6;
    background: #0f172a;
    border-radius: 0.5rem;
    transition: background 150ms ease;
}

.quick-link:hover {
    background: #1e293b;
    color: #60a5fa;
}

.feature-list {
    list-style: none;
    padding: 0;
    display: flex;
    flex-direction: column;
    gap: 0.35rem;
}

.feature-list li {
    font-size: 0.85rem;
    color: #94a3b8;
    padding-left: 1.25rem;
    position: relative;
}

.feature-list li::before {
    content: "✓";
    position: absolute;
    left: 0;
    color: #22c55e;
    font-weight: 700;
}

.error-message {
    color: #ef4444;
    font-size: 0.85rem;
}

.input-group {
    display: flex;
    gap: 0.5rem;
    margin-bottom: 0.75rem;
}

.input-group .input {
    flex: 1;
}

/* --- Blazor Error UI --- */

#blazor-error-ui {
    background: #ef4444;
    color: #fff;
    bottom: 0;
    box-shadow: 0 -2px 8px rgba(0, 0, 0, 0.3);
    display: none;
    left: 0;
    padding: 0.6rem 1.25rem;
    position: fixed;
    width: 100%;
    z-index: 1000;
    font-size: 0.875rem;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 0.75rem;
    top: 0.5rem;
}

.blazor-error-boundary {
    background: #b32121;
    padding: 1rem;
    color: white;
}

.blazor-error-boundary::after {
    content: "An error has occurred.";
}

/* --- Loading Progress --- */

.loading-progress {
    position: absolute;
    display: block;
    width: 8rem;
    height: 8rem;
    inset: 20vh 0 auto 0;
    margin: 0 auto;
}

.loading-progress circle {
    fill: none;
    stroke: #e2e8f0;
    stroke-width: 0.6rem;
    transform-origin: 50% 50%;
    transform: rotate(-90deg);
}

html.dark .loading-progress circle {
    stroke: #334155;
}

.loading-progress circle:last-child {
    stroke: #34d399;
    stroke-dasharray: calc(3.141 * var(--blazor-load-percentage, 0%) * 0.8), 500%;
    transition: stroke-dasharray 0.05s ease-in-out;
}

.loading-progress-text {
    position: absolute;
    text-align: center;
    font-weight: bold;
    inset: calc(20vh + 3.25rem) 0 auto 0.2rem;
    color: #334155;
}

html.dark .loading-progress-text {
    color: #f1f5f9;
}

.loading-progress-text::after {
    content: var(--blazor-load-percentage-text, "Loading");
}

/* --- Validation --- */

.valid.modified:not([type="checkbox"]) {
    outline: 1px solid #22c55e;
}

.invalid {
    outline: 1px solid #ef4444;
}

.validation-message {
    color: #ef4444;
    font-size: 0.8rem;
    margin-top: 0.25rem;
}

/* --- Responsive --- */

@media (max-width: 768px) {
    .card-grid {
        grid-template-columns: 1fr;
    }

    .health-grid {
        grid-template-columns: 1fr;
    }

    .note-list {
        grid-template-columns: 1fr;
    }
}
