/* ============================================
   Ethereal Liaison Design System
   Core tokens & utilities for ChatHost
   ============================================ */

/* --- Design Tokens --- */
:root {
    /* Primary Palette (Material Design 3) */
    --md-background: #f7f9fe;
    --md-surface: #f7f9fe;
    --md-surface-dim: #d7dadf;
    --md-surface-bright: #f7f9fe;
    --md-surface-container-lowest: #ffffff;
    --md-surface-container-low: #f1f4f9;
    --md-surface-container: #ebeef3;
    --md-surface-container-high: #e5e8ed;
    --md-surface-container-highest: #dfe3e8;
    --md-surface-variant: #dfe3e8;

    --md-primary: #006193;
    --md-primary-container: #007bb9;
    --md-on-primary: #ffffff;
    --md-on-primary-container: #fdfcff;
    --md-primary-fixed: #cce5ff;
    --md-primary-fixed-dim: #92ccff;
    --md-inverse-primary: #92ccff;

    --md-secondary: #48626e;
    --md-secondary-container: #cbe7f5;
    --md-secondary-fixed: #cbe7f5;
    --md-on-secondary: #ffffff;
    --md-on-secondary-container: #4e6874;

    --md-tertiary: #8b4c00;
    --md-tertiary-container: #af6100;
    --md-tertiary-fixed: #ffdcc2;
    --md-on-tertiary: #ffffff;

    --md-error: #ba1a1a;
    --md-error-container: #ffdad6;
    --md-on-error: #ffffff;
    --md-on-error-container: #93000a;

    --md-on-background: #181c20;
    --md-on-surface: #181c20;
    --md-on-surface-variant: #3f4850;
    --md-outline: #6f7881;
    --md-outline-variant: #bfc7d2;
    --md-inverse-surface: #2d3135;
    --md-inverse-on-surface: #eef1f6;
    --md-surface-tint: #006497;

    /* Telegram accent */
    --tg-blue: #0088cc;
    --tg-blue-dark: #343a40;

    /* Functional */
    --success: #28a745;
    --success-bg: #ecfdf5;
    --danger: #ba1a1a;

    /* Shadows (tinted, never pure black) */
    --shadow-sm: 0 2px 8px -2px rgba(0, 29, 49, 0.04);
    --shadow-md: 0 8px 24px -4px rgba(0, 29, 49, 0.06);
    --shadow-lg: 0 12px 32px -4px rgba(0, 29, 49, 0.06);
    --shadow-xl: 0 20px 40px -8px rgba(0, 29, 49, 0.08);
    --shadow-primary: 0 8px 24px -4px rgba(0, 97, 147, 0.25);

    /* Roundedness */
    --radius-sm: 4px;
    --radius-md: 8px;
    --radius-lg: 12px;
    --radius-xl: 16px;
    --radius-2xl: 24px;
    --radius-full: 9999px;

    /* Typography */
    --font-headline: 'Manrope', 'Noto Sans', sans-serif;
    --font-body: 'Inter', 'Noto Sans', 'Noto Sans SC', sans-serif;
    --font-label: 'Inter', 'Noto Sans', sans-serif;
}

/* --- Base Reset & Globals --- */
*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

body {
    font-family: var(--font-body);
    color: var(--md-on-surface);
    background-color: var(--md-background);
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body.lang-cn {
    font-family: 'Noto Sans SC', 'Inter', sans-serif;
}

a {
    color: var(--md-primary);
    text-decoration: none;
    transition: color 0.2s ease;
}
a:hover {
    color: var(--md-primary-container);
}

/* --- Material Symbols --- */
.material-symbols-outlined {
    font-variation-settings: 'FILL' 0, 'wght' 400, 'GRAD' 0, 'opsz' 24;
    display: inline-block;
    vertical-align: middle;
    line-height: 1;
}

/* --- Surface Utilities --- */
.surface { background-color: var(--md-surface); }
.surface-dim { background-color: var(--md-surface-dim); }
.surface-container-lowest { background-color: var(--md-surface-container-lowest); }
.surface-container-low { background-color: var(--md-surface-container-low); }
.surface-container { background-color: var(--md-surface-container); }
.surface-container-high { background-color: var(--md-surface-container-high); }
.surface-container-highest { background-color: var(--md-surface-container-highest); }

/* --- Shadow Utilities --- */
.shadow-tonal { box-shadow: var(--shadow-lg); }
.shadow-tonal-sm { box-shadow: var(--shadow-sm); }
.shadow-tonal-md { box-shadow: var(--shadow-md); }
.shadow-primary { box-shadow: var(--shadow-primary); }

/* --- Glass Card --- */
.glass-card {
    background: rgba(255, 255, 255, 0.7);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    border: 1px solid rgba(255, 255, 255, 0.3);
}

.glass-sidebar {
    background: rgba(255, 255, 255, 0.8);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
}

/* --- Typography Classes --- */
.font-headline { font-family: var(--font-headline); }
.font-body { font-family: var(--font-body); }
.font-label { font-family: var(--font-label); }

.text-display { font-size: 2.75rem; font-weight: 800; letter-spacing: -0.02em; font-family: var(--font-headline); }
.text-headline { font-size: 1.5rem; font-weight: 700; letter-spacing: -0.01em; font-family: var(--font-headline); }
.text-title { font-size: 1.125rem; font-weight: 600; font-family: var(--font-body); }
.text-body { font-size: 0.875rem; font-weight: 400; font-family: var(--font-body); }
.text-label { font-size: 0.6875rem; font-weight: 600; letter-spacing: 0.05rem; text-transform: uppercase; font-family: var(--font-label); }

/* --- Color Text --- */
.text-on-surface { color: var(--md-on-surface); }
.text-on-surface-variant { color: var(--md-on-surface-variant); }
.text-primary { color: var(--md-primary); }
.text-outline { color: var(--md-outline); }
.text-error { color: var(--md-error); }

/* --- Buttons --- */
.btn-ethereal-primary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.75rem 1.5rem;
    background: linear-gradient(135deg, var(--md-primary), var(--md-primary-container));
    color: var(--md-on-primary);
    border: none;
    border-radius: var(--radius-lg);
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    box-shadow: var(--shadow-primary);
    transition: all 0.2s ease;
}
.btn-ethereal-primary:hover {
    transform: translateY(-1px);
    box-shadow: 0 12px 28px -4px rgba(0, 97, 147, 0.3);
}
.btn-ethereal-primary:active {
    transform: scale(0.98);
}

.btn-ethereal-secondary {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    background: var(--md-surface-container-high);
    color: var(--md-on-surface);
    border: none;
    border-radius: var(--radius-lg);
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}
.btn-ethereal-secondary:hover {
    background: var(--md-surface-container-highest);
}

.btn-ethereal-tertiary {
    display: inline-flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 1rem;
    background: transparent;
    color: var(--md-primary);
    border: none;
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}
.btn-ethereal-tertiary:hover {
    background: rgba(0, 97, 147, 0.08);
    border-radius: var(--radius-md);
}

.btn-ethereal-danger {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.5rem;
    padding: 0.625rem 1.25rem;
    background: var(--md-error-container);
    color: var(--md-on-error-container);
    border: none;
    border-radius: var(--radius-lg);
    font-family: var(--font-body);
    font-size: 0.875rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.2s ease;
}
.btn-ethereal-danger:hover {
    background: var(--md-error);
    color: var(--md-on-error);
}

/* --- Input Fields --- */
.input-ethereal {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--md-surface-container-low);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 0.875rem;
    color: var(--md-on-surface);
    transition: all 0.2s ease;
    outline: none;
}
.input-ethereal::placeholder {
    color: var(--md-outline);
    opacity: 0.6;
}
.input-ethereal:focus {
    background: var(--md-surface-container-lowest);
    border-color: var(--md-primary);
    box-shadow: 0 0 0 3px rgba(0, 97, 147, 0.15);
}

.input-group-ethereal {
    position: relative;
    display: flex;
    align-items: center;
}
.input-group-ethereal .input-icon {
    position: absolute;
    left: 0.875rem;
    color: var(--md-outline);
    pointer-events: none;
    z-index: 1;
}
.input-group-ethereal .input-ethereal {
    padding-left: 2.75rem;
}

/* --- Cards (Tonal Layering, no borders) --- */
.card-ethereal {
    background: var(--md-surface-container-lowest);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    border: 1px solid transparent;
    padding: 1.5rem;
    transition: all 0.2s ease;
}
.card-ethereal:hover {
    transform: translateY(-2px);
    border-color: rgba(0, 97, 147, 0.1);
}

/* --- Status Orb (not just a dot) --- */
.status-orb {
    width: 12px;
    height: 12px;
    border-radius: 50%;
    display: inline-block;
}
.status-orb.online {
    background: radial-gradient(circle, #28a745 0%, #1e7e34 100%);
    box-shadow: 0 0 8px rgba(40, 167, 69, 0.4);
}
.status-orb.offline {
    background: radial-gradient(circle, #6c757d 0%, #495057 100%);
    box-shadow: 0 0 4px rgba(108, 117, 125, 0.3);
}
.status-orb.danger {
    background: radial-gradient(circle, #dc3545 0%, #c82333 100%);
    box-shadow: 0 0 8px rgba(220, 53, 69, 0.4);
}

/* --- Chips (Metadata Tags) --- */
.chip-ethereal {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.25rem 0.75rem;
    background: var(--md-surface-container-highest);
    border-radius: var(--radius-sm);
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--md-on-surface);
}
.chip-ethereal.primary {
    background: rgba(0, 97, 147, 0.1);
    color: var(--md-primary);
}
.chip-ethereal.success {
    background: #ecfdf5;
    color: #059669;
}
.chip-ethereal.warning {
    background: #fffbeb;
    color: #d97706;
}
.chip-ethereal.error {
    background: var(--md-error-container);
    color: var(--md-on-error-container);
}

/* --- Custom Scrollbar --- */
.custom-scrollbar::-webkit-scrollbar { width: 6px; }
.custom-scrollbar::-webkit-scrollbar-track { background: transparent; }
.custom-scrollbar::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.1); border-radius: 10px; }
.custom-scrollbar:hover::-webkit-scrollbar-thumb { background: rgba(0, 0, 0, 0.2); }

/* --- Mesh Background --- */
.mesh-bg {
    background-color: var(--md-background);
    background-image:
        radial-gradient(at 0% 0%, rgba(0, 97, 147, 0.05) 0px, transparent 50%),
        radial-gradient(at 100% 100%, rgba(0, 97, 147, 0.08) 0px, transparent 50%),
        radial-gradient(at 100% 0%, rgba(203, 231, 245, 0.1) 0px, transparent 50%);
}

/* --- Focus ring for accessibility --- */
.input-focus-ring:focus-within {
    box-shadow: 0 0 0 3px rgba(0, 97, 147, 0.15);
    border-color: var(--md-primary);
}

/* --- Animations --- */
@keyframes floating {
    0% { transform: translateY(0px); }
    50% { transform: translateY(-10px); }
    100% { transform: translateY(0px); }
}

@keyframes fadeInUp {
    from { opacity: 0; transform: translateY(20px); }
    to { opacity: 1; transform: translateY(0); }
}

@keyframes pulse-dot {
    0% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(220, 53, 69, 0.7); }
    70% { transform: scale(1); box-shadow: 0 0 0 6px rgba(220, 53, 69, 0); }
    100% { transform: scale(0.95); box-shadow: 0 0 0 0 rgba(220, 53, 69, 0); }
}

.floating-logo { animation: floating 3s ease-in-out infinite; }
.entrance-fade { animation: fadeInUp 0.6s cubic-bezier(0.16, 1, 0.3, 1); }
.pulse-dot { animation: pulse-dot 2s infinite; }

@media (prefers-reduced-motion) {
    .floating-logo,
    .entrance-fade,
    .pulse-dot {
        animation: none !important;
    }
}

/* --- Dropdown (ethereal style) --- */
.dropdown-ethereal {
    background: var(--md-surface-container-lowest);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-xl);
    border: 1px solid var(--md-outline-variant);
    padding: 0.25rem;
    min-width: 180px;
}
.dropdown-ethereal .dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem;
    border-radius: var(--radius-md);
    font-size: 0.8125rem;
    color: var(--md-on-surface);
    transition: background 0.15s ease;
}
.dropdown-ethereal .dropdown-item:hover {
    background: var(--md-surface-container-low);
}

/* --- Toast Notification --- */
.toast-ethereal {
    position: fixed;
    bottom: 1.5rem;
    right: 1.5rem;
    z-index: 9999;
    display: flex;
    align-items: center;
    gap: 0.75rem;
    background: var(--md-on-surface);
    color: white;
    padding: 1rem 1.5rem;
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    transform: translateY(100px);
    opacity: 0;
    transition: all 0.3s ease;
    pointer-events: none;
}
.toast-ethereal.show {
    transform: translateY(0);
    opacity: 1;
    pointer-events: auto;
}

/* --- Spinner --- */
.spinner-ethereal {
    width: 24px;
    height: 24px;
    border: 3px solid var(--md-surface-container-high);
    border-top-color: var(--md-primary);
    border-radius: 50%;
    animation: spin 0.8s linear infinite;
}

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

/* --- Badge --- */
.badge-ethereal {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 20px;
    height: 20px;
    padding: 0 6px;
    border-radius: var(--radius-full);
    font-size: 0.625rem;
    font-weight: 700;
    line-height: 1;
}
.badge-ethereal.primary {
    background: var(--md-primary);
    color: var(--md-on-primary);
}
.badge-ethereal.error {
    background: var(--md-error);
    color: var(--md-on-error);
}
.badge-ethereal.success {
    background: var(--success);
    color: white;
}

/* --- Ghost Border (accessibility fallback) --- */
.ghost-border {
    border: 1px solid rgba(191, 199, 210, 0.15);
}

/* --- Section Label (Functional label, uppercase) --- */
.section-label {
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.05rem;
    text-transform: uppercase;
    color: var(--md-outline);
}

/* --- Alert (Ethereal Style) --- */
.alert-ethereal {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.875rem 1rem;
    border-radius: var(--radius-lg);
    font-size: 0.875rem;
}
.alert-ethereal.danger {
    background: var(--md-error-container);
    color: var(--md-on-error-container);
}
.alert-ethereal.success {
    background: #ecfdf5;
    color: #059669;
}
.alert-ethereal.info {
    background: var(--md-primary-fixed);
    color: var(--md-primary);
}

/* --- Table (Ethereal no-border) --- */
.table-ethereal {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0 0.5rem;
}
.table-ethereal thead th {
    font-size: 0.6875rem;
    font-weight: 700;
    letter-spacing: 0.05rem;
    text-transform: uppercase;
    color: var(--md-outline);
    padding: 0.5rem 1rem;
    background: none;
    border: none;
}
.table-ethereal tbody tr {
    background: var(--md-surface-container-lowest);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: all 0.15s ease;
}
.table-ethereal tbody tr:hover {
    background: var(--md-surface-container-low);
    transform: translateY(-1px);
}
.table-ethereal tbody td {
    padding: 0.875rem 1rem;
    font-size: 0.875rem;
    border: none;
}
.table-ethereal tbody td:first-child { border-radius: var(--radius-lg) 0 0 var(--radius-lg); }
.table-ethereal tbody td:last-child { border-radius: 0 var(--radius-lg) var(--radius-lg) 0; }

/* --- Modal (Ethereal) --- */
.modal-ethereal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.3);
    backdrop-filter: blur(4px);
    z-index: 9998;
    display: flex;
    align-items: center;
    justify-content: center;
}
.modal-ethereal {
    background: var(--md-surface-container-lowest);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-xl);
    max-width: 500px;
    width: 90%;
    max-height: 90vh;
    overflow-y: auto;
}
.modal-ethereal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 1.25rem 1.5rem;
}
.modal-ethereal-body {
    padding: 0 1.5rem 1.5rem;
}
.modal-ethereal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 0.5rem;
    padding: 1rem 1.5rem;
}

/* --- Form Elements (Ethereal) --- */
.form-group-ethereal {
    margin-bottom: 1rem;
}
.form-group-ethereal label {
    display: block;
    font-size: 0.8125rem;
    font-weight: 600;
    color: var(--md-on-surface);
    margin-bottom: 0.375rem;
}
.form-group-ethereal .input-ethereal {
    width: 100%;
}

.select-ethereal {
    width: 100%;
    padding: 0.625rem 2rem 0.625rem 0.75rem;
    background: var(--md-surface-container-low);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 0.8125rem;
    font-weight: 500;
    color: var(--md-on-surface);
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' fill='%236f7881' viewBox='0 0 16 16'%3E%3Cpath d='M7.247 11.14 2.451 5.658C1.885 5.013 2.345 4 3.204 4h9.592a1 1 0 0 1 .753 1.659l-4.796 5.48a1 1 0 0 1-1.506 0z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.75rem center;
    background-size: 12px;
    transition: all 0.2s ease;
    outline: none;
    cursor: pointer;
}
.select-ethereal:focus {
    background-color: var(--md-surface-container-lowest);
    border-color: var(--md-primary);
    box-shadow: 0 0 0 3px rgba(0, 97, 147, 0.15);
}

.checkbox-ethereal {
    appearance: none;
    width: 20px;
    height: 20px;
    border: 2px solid var(--md-outline-variant);
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: all 0.15s ease;
    position: relative;
}
.checkbox-ethereal:checked {
    background: var(--md-primary);
    border-color: var(--md-primary);
}
.checkbox-ethereal:checked::after {
    content: '✓';
    color: white;
    font-size: 12px;
    position: absolute;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
}

.switch-ethereal {
    appearance: none;
    width: 44px;
    height: 24px;
    background: var(--md-surface-container-highest);
    border-radius: var(--radius-full);
    cursor: pointer;
    transition: all 0.2s ease;
    position: relative;
}
.switch-ethereal::after {
    content: '';
    position: absolute;
    top: 2px;
    left: 2px;
    width: 20px;
    height: 20px;
    background: white;
    border-radius: 50%;
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
    transition: all 0.2s ease;
}
.switch-ethereal:checked {
    background: var(--md-primary);
}
.switch-ethereal:checked::after {
    left: 22px;
}

/* --- Textarea Ethereal --- */
.textarea-ethereal {
    width: 100%;
    padding: 0.75rem 1rem;
    background: var(--md-surface-container-low);
    border: 2px solid transparent;
    border-radius: var(--radius-md);
    font-family: var(--font-body);
    font-size: 0.875rem;
    color: var(--md-on-surface);
    resize: vertical;
    outline: none;
    transition: all 0.2s ease;
    min-height: 80px;
}
.textarea-ethereal::placeholder { color: var(--md-outline); opacity: 0.6; }
.textarea-ethereal:focus {
    background: var(--md-surface-container-lowest);
    border-color: var(--md-primary);
    box-shadow: 0 0 0 3px rgba(0, 97, 147, 0.15);
}

/* --- Progress Bar --- */
.progress-ethereal {
    width: 100%;
    height: 8px;
    background: var(--md-surface-container);
    border-radius: var(--radius-full);
    overflow: hidden;
}
.progress-ethereal-bar {
    height: 100%;
    border-radius: var(--radius-full);
    background: linear-gradient(90deg, var(--md-primary), var(--md-primary-container));
    transition: width 0.3s ease;
}
