/* Core application stylesheet. Uses only CSS variables from themes.css
   for color - never hard-coded colors (spec section 27, 31). */

* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

body {
    background: var(--background);
    color: var(--text);
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    transition: background-color .2s ease, color .2s ease;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .5em; font-weight: 650; letter-spacing: -0.01em; }

.app-shell { display: flex; min-height: 100vh; }

/* ---- Sidebar nav ---- */
.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: var(--surface);
    border-right: 1px solid var(--border);
    padding: 20px 14px;
    position: sticky;
    top: 0;
    height: 100vh;
    overflow-y: auto;
}
.sidebar .brand { display: flex; align-items: center; gap: 10px; padding: 6px 8px 20px; font-weight: 700; font-size: 1.05rem; }
.sidebar .brand .dot { width: 10px; height: 10px; border-radius: 50%; background: var(--primary); }
.nav-group { margin-bottom: 18px; }
.nav-group-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); padding: 0 10px 6px; }
.nav-link {
    display: flex; align-items: center; gap: 10px;
    padding: 9px 10px; border-radius: 8px; color: var(--text);
    font-size: .92rem; font-weight: 500;
}
.nav-link:hover { background: var(--surface-secondary); text-decoration: none; }
.nav-link.active { background: var(--primary); color: var(--primary-contrast); }

/* ---- Topbar nav ---- */
.topbar {
    display: flex; align-items: center; justify-content: space-between;
    background: var(--surface); border-bottom: 1px solid var(--border);
    padding: 10px 20px; position: sticky; top: 0; z-index: 10;
}
.topbar .links { display: flex; gap: 4px; flex-wrap: wrap; }
.topbar .links a { padding: 7px 12px; border-radius: 8px; color: var(--text); font-size: .88rem; font-weight: 500; }
.topbar .links a:hover { background: var(--surface-secondary); text-decoration: none; }
.topbar .links a.active { background: var(--primary); color: var(--primary-contrast); }

.main-area { flex: 1; min-width: 0; }
.page { padding: 28px; max-width: 1180px; margin: 0 auto; }

.topbar-user, .sidebar-user { display: flex; align-items: center; gap: 10px; }
.avatar { border-radius: 50%; object-fit: cover; border: 1px solid var(--border); }

/* ---- Cards ---- */
.card {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    padding: 22px;
    box-shadow: var(--shadow);
}
.card + .card { margin-top: 18px; }

/* ---- Forms ---- */
label { display: block; font-size: .84rem; font-weight: 600; margin-bottom: 6px; color: var(--text-muted); }
input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
    width: 100%; padding: 10px 12px; border-radius: 9px;
    border: 1px solid var(--border); background: var(--surface-secondary);
    color: var(--text); font-size: .93rem; font-family: inherit;
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--primary); outline-offset: 1px; }
.field { margin-bottom: 16px; }
.form-actions { display: flex; gap: 10px; margin-top: 4px; }
.help-text { font-size: .8rem; color: var(--text-muted); margin-top: 4px; }

.btn {
    display: inline-flex; align-items: center; justify-content: center; gap: 8px;
    padding: 10px 16px; border-radius: 9px; border: 1px solid transparent;
    font-weight: 600; font-size: .9rem; cursor: pointer;
    background: var(--primary); color: var(--primary-contrast);
}
.btn:hover { filter: brightness(1.08); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn-secondary { background: var(--surface-secondary); color: var(--text); border-color: var(--border); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-block { width: 100%; }
.btn-sm { padding: 6px 10px; font-size: .8rem; }

/* ---- Badges / alerts ---- */
.badge { display: inline-block; padding: 3px 9px; border-radius: 999px; font-size: .74rem; font-weight: 700; letter-spacing: .02em; }
.badge-success { background: color-mix(in srgb, var(--success) 18%, transparent); color: var(--success); }
.badge-danger { background: color-mix(in srgb, var(--danger) 18%, transparent); color: var(--danger); }
.badge-muted { background: var(--surface-secondary); color: var(--text-muted); }
.badge-primary { background: color-mix(in srgb, var(--primary) 18%, transparent); color: var(--primary); }

.alert { padding: 12px 14px; border-radius: 9px; margin-bottom: 16px; font-size: .88rem; border: 1px solid transparent; }
.alert-error { background: color-mix(in srgb, var(--danger) 12%, var(--surface)); border-color: color-mix(in srgb, var(--danger) 35%, transparent); color: var(--danger); }
.alert-success { background: color-mix(in srgb, var(--success) 12%, var(--surface)); border-color: color-mix(in srgb, var(--success) 35%, transparent); color: var(--success); }

/* ---- Tables ---- */
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); font-size: .87rem; }
th { color: var(--text-muted); font-weight: 600; font-size: .76rem; text-transform: uppercase; letter-spacing: .04em; }
tr:hover td { background: var(--surface-secondary); }
.table-wrap { overflow-x: auto; }

.pagination { display: flex; gap: 6px; margin-top: 16px; flex-wrap: wrap; }
.pagination a, .pagination span { padding: 6px 11px; border-radius: 7px; border: 1px solid var(--border); font-size: .82rem; }
.pagination .current { background: var(--primary); color: var(--primary-contrast); border-color: var(--primary); }

.empty-state { text-align: center; padding: 40px 20px; color: var(--text-muted); }

/* ---- Lookup result card ---- */
.result-card {
    position: relative;
    overflow: hidden;
    border-radius: var(--radius);
    border: 1px solid var(--border);
    background: var(--surface);
    padding: 26px;
    box-shadow: var(--shadow);
}
.result-card .logo-watermark {
    position: absolute; inset: 0;
    background-repeat: no-repeat; background-position: right -20px center; background-size: 260px;
    opacity: .10; filter: grayscale(15%);
    pointer-events: none;
}
.result-card::after {
    content: ""; position: absolute; inset: 0;
    background: linear-gradient(120deg, var(--surface) 35%, transparent 85%);
    pointer-events: none;
}
.result-card .result-inner { position: relative; z-index: 1; }
.result-number { font-size: 1.5rem; font-weight: 700; margin-bottom: 2px; }
.result-carrier-row { display: flex; align-items: center; gap: 10px; margin-bottom: 18px; }
.result-carrier-row img { height: 26px; max-width: 90px; object-fit: contain; }
.result-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(190px, 1fr)); gap: 14px 22px; }
.result-field .field-label { font-size: .72rem; text-transform: uppercase; letter-spacing: .06em; color: var(--text-muted); margin-bottom: 3px; }
.result-field .field-value { font-size: .93rem; font-weight: 600; word-break: break-word; }
.result-section-title { font-size: .78rem; text-transform: uppercase; letter-spacing: .08em; color: var(--text-muted); margin: 20px 0 10px; border-top: 1px solid var(--border); padding-top: 16px; }
.result-section-title:first-of-type { border-top: none; padding-top: 0; margin-top: 0; }

/* ---- Toasts ---- */
#toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 999; display: flex; flex-direction: column; gap: 10px; }
.toast { background: var(--surface); border: 1px solid var(--border); border-radius: 9px; padding: 12px 16px; box-shadow: var(--shadow); font-size: .87rem; min-width: 240px; }
.toast.error { border-color: var(--danger); color: var(--danger); }
.toast.success { border-color: var(--success); color: var(--success); }

/* ---- Auth pages ---- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 24px; background: var(--background); }
.auth-card { width: 100%; max-width: 400px; }
.auth-brand { text-align: center; margin-bottom: 22px; }
.auth-brand .dot { width: 12px; height: 12px; border-radius: 50%; background: var(--primary); display: inline-block; margin-right: 8px; }
.divider { display: flex; align-items: center; gap: 12px; margin: 18px 0; color: var(--text-muted); font-size: .8rem; }
.divider::before, .divider::after { content: ""; flex: 1; height: 1px; background: var(--border); }
.discord-btn { background: #5865F2; color: #fff; }

/* ---- Theme swatches ---- */
.theme-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); gap: 14px; }
.theme-option { border: 2px solid var(--border); border-radius: 12px; padding: 14px; cursor: pointer; }
.theme-option.selected { border-color: var(--primary); }
.theme-swatch { height: 46px; border-radius: 8px; margin-bottom: 10px; border: 1px solid rgba(0,0,0,0.1); }

/* ---- Misc ---- */
.muted { color: var(--text-muted); }
.stack { display: flex; flex-direction: column; gap: 10px; }
.row { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }
.space-between { display: flex; align-items: center; justify-content: space-between; gap: 10px; flex-wrap: wrap; }
.mt-0 { margin-top: 0; }
.checklist { list-style: none; padding: 0; margin: 0; }
.checklist li { display: flex; align-items: center; gap: 10px; padding: 8px 0; border-bottom: 1px solid var(--border); font-size: .88rem; }
.check-ok { color: var(--success); }
.check-fail { color: var(--danger); }

@media (max-width: 860px) {
    .sidebar { display: none; }
    .page { padding: 16px; }
    .result-grid { grid-template-columns: 1fr 1fr; }
}

/* ==========================================================
   Animations & interactive polish
   ========================================================== */

@keyframes fadeSlideUp {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: translateY(0); }
}
@keyframes fadeIn {
    from { opacity: 0; }
    to { opacity: 1; }
}
@keyframes toastIn {
    from { opacity: 0; transform: translateX(24px) scale(.97); }
    to { opacity: 1; transform: translateX(0) scale(1); }
}
@keyframes pop {
    0% { transform: scale(.85); opacity: 0; }
    60% { transform: scale(1.04); opacity: 1; }
    100% { transform: scale(1); }
}
@keyframes shimmer {
    0% { background-position: -200% 0; }
    100% { background-position: 200% 0; }
}

.page > * { animation: fadeSlideUp .38s cubic-bezier(.2,.7,.3,1) both; }
.page > *:nth-child(2) { animation-delay: .04s; }
.page > *:nth-child(3) { animation-delay: .08s; }
.page > *:nth-child(4) { animation-delay: .12s; }

.card {
    transition: transform .22s ease, box-shadow .22s ease, border-color .22s ease;
}
.card:hover {
    transform: translateY(-2px);
    border-color: color-mix(in srgb, var(--primary) 35%, var(--border));
}

/* ---- Cool buttons ---- */
.btn {
    position: relative;
    overflow: hidden;
    transition: transform .16s cubic-bezier(.3,.7,.4,1.5), box-shadow .2s ease, filter .16s ease, background .16s ease;
}
.btn::before {
    content: "";
    position: absolute;
    inset: 0;
    background: linear-gradient(120deg, transparent 30%, rgba(255,255,255,.28) 50%, transparent 70%);
    background-size: 220% 100%;
    background-position: 200% 0;
    opacity: 0;
    transition: opacity .2s ease;
    pointer-events: none;
}
.btn:hover {
    transform: translateY(-1px) scale(1.015);
    box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--primary) 60%, transparent);
}
.btn:hover::before {
    opacity: 1;
    animation: shimmer 1.1s ease;
}
.btn:active {
    transform: translateY(0) scale(.98);
    transition-duration: .05s;
}
.btn:focus-visible {
    outline: 2px solid var(--primary);
    outline-offset: 2px;
}
.btn-danger:hover { box-shadow: 0 8px 20px -8px color-mix(in srgb, var(--danger) 60%, transparent); }

.nav-link {
    transition: background .18s ease, color .18s ease, transform .18s ease;
}
.nav-link:hover { transform: translateX(2px); }

input[type=text], input[type=email], input[type=password], input[type=number], select, textarea {
    transition: border-color .18s ease, box-shadow .18s ease;
}
input:focus, select:focus, textarea:focus {
    box-shadow: 0 0 0 4px color-mix(in srgb, var(--primary) 18%, transparent);
}

.badge { transition: transform .15s ease; }
.result-card { animation: fadeSlideUp .32s cubic-bezier(.2,.7,.3,1) both; }
.toast { animation: toastIn .28s cubic-bezier(.2,.7,.3,1) both; }
.avatar { transition: transform .18s ease; }
.avatar:hover { transform: scale(1.08); }

/* ---- Sliding pill tab bar (used by settings-tabs.php) ---- */
.tab-slider {
    position: relative;
    display: inline-flex;
    gap: 2px;
    background: var(--surface-secondary);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px;
    margin-bottom: 20px;
}
.tab-slider .tab-pill {
    position: absolute;
    top: 4px; bottom: 4px; left: 4px;
    width: 0;
    border-radius: 999px;
    background: var(--primary);
    box-shadow: 0 4px 14px -4px color-mix(in srgb, var(--primary) 70%, transparent);
    transition: transform .28s cubic-bezier(.2,.8,.2,1), width .28s cubic-bezier(.2,.8,.2,1);
    z-index: 0;
}
.tab-slider a {
    position: relative;
    z-index: 1;
    padding: 8px 16px;
    border-radius: 999px;
    font-size: .86rem;
    font-weight: 600;
    color: var(--text-muted);
    transition: color .2s ease;
    white-space: nowrap;
}
.tab-slider a:hover { text-decoration: none; color: var(--text); }
.tab-slider a.active { color: var(--primary-contrast); }

/* ---- Sliding segmented control (nav style, etc) ---- */
.segmented {
    position: relative;
    display: inline-flex;
    background: var(--surface-secondary);
    border: 1px solid var(--border);
    border-radius: 999px;
    padding: 4px;
}
.segmented .segment-pill {
    position: absolute;
    top: 4px; bottom: 4px; left: 4px;
    width: 0;
    border-radius: 999px;
    background: var(--primary);
    box-shadow: 0 4px 14px -4px color-mix(in srgb, var(--primary) 70%, transparent);
    transition: transform .26s cubic-bezier(.2,.8,.2,1), width .26s cubic-bezier(.2,.8,.2,1);
    z-index: 0;
}
.segmented label {
    position: relative;
    z-index: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    padding: 9px 18px;
    border-radius: 999px;
    font-size: .86rem;
    font-weight: 600;
    color: var(--text-muted);
    cursor: pointer;
    margin-bottom: 0;
    transition: color .2s ease;
    white-space: nowrap;
}
.segmented label.active { color: var(--primary-contrast); }
.segmented input[type=radio] {
    position: absolute;
    opacity: 0;
    width: 0; height: 0;
}

/* ---- Theme swatch selection polish ---- */
.theme-option {
    transition: transform .18s cubic-bezier(.2,.8,.3,1.2), border-color .18s ease, box-shadow .18s ease;
    position: relative;
}
.theme-option:hover { transform: translateY(-3px); }
.theme-option.selected {
    box-shadow: 0 6px 18px -6px color-mix(in srgb, var(--primary) 55%, transparent);
}
.theme-option.selected::after {
    content: "\2713";
    position: absolute;
    top: 8px; right: 10px;
    width: 20px; height: 20px;
    display: flex; align-items: center; justify-content: center;
    background: var(--primary);
    color: var(--primary-contrast);
    border-radius: 50%;
    font-size: .7rem;
    font-weight: 700;
    animation: pop .3s cubic-bezier(.3,.9,.3,1.4);
}
.theme-swatch { transition: transform .18s ease; }
.theme-option:hover .theme-swatch { transform: scale(1.03); }

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