/* ==========================================================================
   Sytronic Chat — shared base styles
   Design tokens live in templates/partials/theme.html (light + dark).
   ========================================================================== */

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

html, body { margin: 0; padding: 0; }

html {
    -webkit-text-size-adjust: 100%;
    text-size-adjust: 100%;
    scroll-behavior: smooth;
}

body {
    font-family: 'Nunito', 'Noto Sans SC', 'PingFang SC', 'Microsoft YaHei', system-ui, sans-serif;
    background: var(--surface);
    color: var(--on-surface);
    font-size: 15px;
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    overflow-wrap: break-word;
}

h1, h2, h3, h4, p, figure, blockquote { margin: 0; }
ul, ol { margin: 0; padding: 0; }
img, svg { display: block; max-width: 100%; }
button, input, textarea, select { font: inherit; color: inherit; }
button { cursor: pointer; }
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: none; }
::selection { background: color-mix(in srgb, var(--primary) 28%, transparent); }

:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}

.hidden, [hidden] { display: none !important; }

.sr-only {
    position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
    overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0;
}

.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }

/* --------------------------------------------------------------------------
   Icons (inline SVG sprite)
   -------------------------------------------------------------------------- */
.icon-sprite { position: absolute; width: 0; height: 0; overflow: hidden; }

.icon {
    width: 20px; height: 20px; flex: none;
    fill: none; stroke: currentColor;
    stroke-width: 1.8; stroke-linecap: round; stroke-linejoin: round;
}

.icon-sm { width: 16px; height: 16px; }
.icon-lg { width: 24px; height: 24px; }

/* --------------------------------------------------------------------------
   Small section labels (settings / auth pages)
   -------------------------------------------------------------------------- */
.eyebrow {
    display: inline-flex; align-items: center; gap: 8px;
    padding: 7px 14px; border-radius: 999px;
    border: 1px solid var(--outline-v);
    background: color-mix(in srgb, var(--surface-cl) 70%, transparent);
    font-size: 12px; font-weight: 800; letter-spacing: .01em; color: var(--on-sv);
    box-shadow: var(--shadow-sm);
}
.eyebrow-plain {
    border: 0; background: none; padding: 0; box-shadow: none;
    color: var(--primary); font-size: 12px; font-weight: 900;
    letter-spacing: .16em; text-transform: uppercase;
}

/* --------------------------------------------------------------------------
   Brand
   -------------------------------------------------------------------------- */
.brand {
    display: inline-flex; align-items: center; gap: 10px;
    color: var(--on-surface); font-weight: 900; letter-spacing: -.02em;
}
.brand:hover { color: var(--on-surface); }
.brand-logo {
    width: 36px; height: 36px; border-radius: 11px;
    box-shadow: 0 4px 12px -4px color-mix(in srgb, var(--primary) 55%, transparent);
    flex: none;
}
.brand-name { font-size: 17px; line-height: 1.1; }
.brand-name em {
    font-style: normal;
    color: var(--primary);
}
.brand-sub {
    display: block; font-size: 10px; font-weight: 800; letter-spacing: .14em;
    text-transform: uppercase; color: var(--outline);
}

/* --------------------------------------------------------------------------
   Presence indicators
   -------------------------------------------------------------------------- */
.status-dot {
    display: inline-block; width: 8px; height: 8px; flex: none;
    border-radius: 50%; background: var(--outline-v);
}
.status-dot.online {
    background: var(--primary);
    box-shadow: 0 0 0 2px color-mix(in srgb, var(--primary) 18%, transparent);
}
.status-dot.offline { background: var(--outline-v); }
.presence-emoji-inline {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 14px; height: 14px; flex: none;
    font-size: 12px; line-height: 1;
}

/* --------------------------------------------------------------------------
   Buttons
   -------------------------------------------------------------------------- */
.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    min-height: 42px; padding: 0 18px; border-radius: 13px;
    border: 1px solid transparent; background: transparent;
    font-size: 14px; font-weight: 800; line-height: 1; white-space: nowrap;
    transition: transform .16s, background .18s, color .18s, box-shadow .18s, border-color .18s;
    user-select: none;
}
.btn:active { transform: translateY(1px) scale(.995); }
.btn:disabled, .btn[aria-disabled="true"] { opacity: .55; pointer-events: none; }

.btn-primary {
    background: var(--primary); color: var(--on-primary);
    box-shadow: 0 6px 16px -8px color-mix(in srgb, var(--primary) 80%, transparent),
                inset 0 1px 0 rgba(255, 255, 255, .18);
}
.btn-primary:hover { background: color-mix(in srgb, var(--primary) 88%, #000); }

.btn-tonal { background: var(--primary-container); color: var(--on-primary-container); }
.btn-tonal:hover { background: color-mix(in srgb, var(--primary-container) 82%, var(--primary) 18%); }

.btn-ghost { border-color: var(--outline-v); background: var(--surface-cl); color: var(--on-surface); }
.btn-ghost:hover { background: var(--surface-ch); }

.btn-quiet { color: var(--on-sv); }
.btn-quiet:hover { background: var(--surface-ch); color: var(--on-surface); }

.btn-danger { background: var(--danger-container); color: var(--danger); }
.btn-danger:hover { background: color-mix(in srgb, var(--danger-container) 85%, var(--danger) 15%); }

.btn-lg { min-height: 50px; padding: 0 24px; font-size: 15px; border-radius: 16px; }
.btn-block { width: 100%; }

.icon-btn {
    display: inline-flex; align-items: center; justify-content: center;
    width: 40px; height: 40px; flex: none;
    border: 1px solid transparent; border-radius: 12px;
    background: transparent; color: var(--on-sv);
    transition: background .18s, color .18s, border-color .18s;
}
.icon-btn:hover { background: var(--surface-ch); color: var(--on-surface); }
.icon-btn:active { transform: scale(.96); }
.icon-btn.filled { background: var(--primary); color: var(--on-primary); }
.icon-btn.filled:hover { background: color-mix(in srgb, var(--primary) 88%, #000); }

/* --------------------------------------------------------------------------
   Avatars
   -------------------------------------------------------------------------- */
.avatar {
    --size: 40px;
    position: relative; display: inline-flex; align-items: center; justify-content: center;
    width: var(--size); height: var(--size); flex: none;
    border-radius: 50%; overflow: hidden;
    background: var(--surface-ch);
    color: var(--on-sv); font-size: calc(var(--size) * .38); font-weight: 900;
    letter-spacing: -.02em; line-height: 1;
    user-select: none;
}
.avatar img {
    position: absolute; inset: 0; width: 100%; height: 100%;
    object-fit: cover; z-index: 1;
}
.avatar-initial { display: none; }
.avatar-lg { --size: 52px; }
.avatar-xl { --size: 92px; }
.avatar-sm { --size: 32px; }

.avatar-wrap { position: relative; flex: none; display: inline-flex; }
.avatar-wrap .presence-dot {
    position: absolute; right: 2px; bottom: 2px; z-index: 3; width: 11px; height: 11px;
    border-radius: 50%; background: var(--outline);
    border: 2px solid var(--surface-clo);
}
.avatar-wrap .presence-dot.online {
    background: var(--primary);
    box-shadow: 0 0 0 3px color-mix(in srgb, var(--primary) 16%, transparent);
}

/* --------------------------------------------------------------------------
   Toast
   -------------------------------------------------------------------------- */
.toast {
    position: fixed; left: 50%; bottom: 28px; z-index: 300;
    transform: translate(-50%, 24px); opacity: 0; pointer-events: none;
    display: flex; align-items: center; gap: 9px;
    max-width: min(520px, calc(100vw - 32px));
    padding: 12px 20px; border-radius: 14px;
    background: var(--on-surface); color: var(--surface);
    font-size: 13.5px; font-weight: 700; line-height: 1.4;
    box-shadow: var(--shadow-lg);
    transition: opacity .2s, transform .24s cubic-bezier(.2, .8, .25, 1);
}
.toast.show { opacity: 1; transform: translate(-50%, 0); }
.toast .icon { width: 17px; height: 17px; }
.toast.error { background: var(--danger); color: #fff; }

/* --------------------------------------------------------------------------
   Modal
   -------------------------------------------------------------------------- */
.modal {
    position: fixed; inset: 0; z-index: 200;
    display: grid; place-items: center; padding: 20px;
    background: color-mix(in srgb, #000 38%, transparent);
    -webkit-backdrop-filter: blur(5px); backdrop-filter: blur(5px);
    animation: fade-in .18s ease both;
}
.modal-card {
    width: min(520px, 100%);
    max-height: min(640px, calc(100dvh - 40px));
    display: flex; flex-direction: column;
    background: var(--surface-cl);
    border: 1px solid var(--outline-v);
    border-radius: 24px;
    box-shadow: var(--shadow-lg);
    overflow: hidden;
    animation: modal-in .24s cubic-bezier(.2, .9, .3, 1) both;
}
.modal-head {
    display: flex; align-items: center; gap: 12px;
    padding: 18px 20px 14px;
}
.modal-head h2 { flex: 1; font-size: 17px; font-weight: 900; letter-spacing: -.01em; }
.modal-body { padding: 0 20px 20px; overflow-y: auto; }
.modal-foot {
    display: flex; justify-content: flex-end; gap: 10px;
    padding: 14px 20px; border-top: 1px solid var(--outline-v);
    background: var(--surface-clo);
}
.modal-note {
    display: flex; gap: 8px; align-items: flex-start;
    padding: 12px 14px; border-radius: 12px;
    background: var(--surface-clo); color: var(--on-sv);
    font-size: 12.5px; line-height: 1.5;
}
.modal-note .icon { width: 16px; height: 16px; margin-top: 1px; color: var(--primary); }

@keyframes fade-in { from { opacity: 0; } to { opacity: 1; } }
@keyframes modal-in { from { opacity: 0; transform: translateY(10px) scale(.985); } to { opacity: 1; transform: none; } }

/* --------------------------------------------------------------------------
   Forms
   -------------------------------------------------------------------------- */
.field { display: flex; flex-direction: column; gap: 7px; }
.field label { font-size: 12.5px; font-weight: 800; color: var(--on-sv); }
.input {
    width: 100%; min-height: 44px; padding: 0 15px;
    border: 1px solid var(--outline-v); border-radius: 13px;
    background: var(--surface); color: var(--on-surface);
    font-size: 14px; transition: border-color .18s, box-shadow .18s, background .18s;
}
.input::placeholder { color: var(--outline); }
.input:focus { outline: none; border-color: var(--primary); box-shadow: var(--ring); background: var(--surface-cl); }

/* --------------------------------------------------------------------------
   Misc
   -------------------------------------------------------------------------- */
.divider { height: 1px; background: var(--outline-v); border: 0; margin: 0; }
.kbd {
    display: inline-flex; align-items: center; justify-content: center;
    min-width: 20px; height: 20px; padding: 0 5px;
    border: 1px solid var(--outline-v); border-bottom-width: 2px; border-radius: 6px;
    background: var(--surface-cl); color: var(--on-sv);
    font-size: 11px; font-weight: 800;
}
.spinner {
    width: 18px; height: 18px; border-radius: 50%;
    border: 2px solid color-mix(in srgb, currentColor 25%, transparent);
    border-top-color: currentColor;
    animation: spin .7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

.skeleton {
    background: linear-gradient(90deg, var(--surface-c) 25%, var(--surface-ch) 50%, var(--surface-c) 75%);
    background-size: 200% 100%;
    animation: shimmer 1.4s ease infinite;
    border-radius: 10px;
}
@keyframes shimmer { from { background-position: 200% 0; } to { background-position: -200% 0; } }

@media (prefers-reduced-motion: reduce) {
    *, *::before, *::after {
        animation-duration: .001ms !important;
        animation-iteration-count: 1 !important;
        transition-duration: .001ms !important;
        scroll-behavior: auto !important;
    }
}
