/* ═══════════════════════════════════════════════════════════
   Keymaster — Reffinet Design System (Dark + Light)
   ═══════════════════════════════════════════════════════════ */

:root {
    --accent: #6366f1;
    --accent2: #8b5cf6;
    --teal: #14b8a6;
    --green: #10b981;
    --red: #ef4444;
    --yellow: #f59e0b;
    --blue: #3b82f6;
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --ease: cubic-bezier(0.22, 1, 0.36, 1);
    --fast: 0.2s;
    --normal: 0.35s;
    --topbar-h: 64px;
}

/* ── Dark Theme (default) ─────────────────────────────────── */
body.theme-dark,
body:not(.theme-light) {
    --bg: #0a0e1a;
    --bg-card: rgba(17, 26, 46, 0.85);
    --bg-item: #0d1525;
    --bg-hover: #162040;
    --bg-input: #0d1525;
    --text: #e8ecf4;
    --text2: #7c8db5;
    --text3: #4b5975;
    --border: #1a2744;
    --border2: #243352;
    --glow-1: rgba(99, 102, 241, 0.12);
    --glow-2: rgba(139, 92, 246, 0.08);
    --topbar-bg: rgba(10, 14, 26, 0.88);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.35);
    --alert-success-bg: rgba(16, 185, 129, 0.12);
    --alert-success-text: #6ee7b7;
    --alert-error-bg: rgba(239, 68, 68, 0.12);
    --alert-error-text: #fca5a5;
    --alert-info-bg: rgba(59, 130, 246, 0.12);
    --alert-info-text: #93c5fd;
}

/* ── Light Theme ──────────────────────────────────────────── */
body.theme-light {
    --bg: #f0f2f8;
    --bg-card: rgba(255, 255, 255, 0.92);
    --bg-item: #f8f9fc;
    --bg-hover: #eef1f8;
    --bg-input: #ffffff;
    --text: #1a1f36;
    --text2: #5a6482;
    --text3: #8b95ad;
    --border: #dde3f0;
    --border2: #c8d0e4;
    --glow-1: rgba(99, 102, 241, 0.06);
    --glow-2: rgba(139, 92, 246, 0.04);
    --topbar-bg: rgba(255, 255, 255, 0.92);
    --shadow: 0 8px 32px rgba(0, 0, 0, 0.08);
    --alert-success-bg: #d1fae5;
    --alert-success-text: #065f46;
    --alert-error-bg: #fee2e2;
    --alert-error-text: #991b1b;
    --alert-info-bg: #dbeafe;
    --alert-info-text: #1e40af;
}

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

html {
    scroll-behavior: smooth;
}

body {
    font-family: "Inter", -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
    -webkit-font-smoothing: antialiased;
    transition: background var(--normal) var(--ease), color var(--normal) var(--ease);
}

/* Background glows */
.bg-glow {
    position: fixed;
    inset: 0;
    pointer-events: none;
    z-index: 0;
    overflow: hidden;
}

.bg-glow::before {
    content: "";
    position: absolute;
    top: -200px;
    left: -100px;
    width: 600px;
    height: 600px;
    background: radial-gradient(circle, var(--glow-1), transparent 70%);
}

.bg-glow::after {
    content: "";
    position: absolute;
    bottom: -200px;
    right: -100px;
    width: 500px;
    height: 500px;
    background: radial-gradient(circle, var(--glow-2), transparent 70%);
}

/* ── Topbar ───────────────────────────────────────────────── */
.topbar {
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    z-index: 100;
    height: var(--topbar-h);
    background: var(--topbar-bg);
    backdrop-filter: blur(24px) saturate(1.4);
    -webkit-backdrop-filter: blur(24px) saturate(1.4);
    border-bottom: 1px solid var(--border);
    display: flex;
    align-items: center;
    transition: background var(--normal) var(--ease);
}

.topbar-inner {
    width: 100%;
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
}

.topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 15px;
    color: var(--text);
    text-decoration: none;
    letter-spacing: -0.3px;
}

.topbar-brand-icon {
    width: 32px;
    height: 32px;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    display: grid;
    place-items: center;
    font-size: 16px;
    box-shadow: 0 4px 12px rgba(99, 102, 241, 0.35);
}

.topbar-brand span {
    background: linear-gradient(132deg, var(--text) 0%, var(--accent) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: 12px;
    flex-wrap: wrap;
}

.topbar-user {
    font-size: 13px;
    color: var(--text2);
}

.topbar-user strong {
    color: var(--text);
}

/* ── Layout ───────────────────────────────────────────────── */
.page-wrap {
    position: relative;
    z-index: 1;
    min-height: 100vh;
}

.page-wrap--dashboard {
    padding-top: calc(var(--topbar-h) + 32px);
    padding-bottom: 48px;
}

.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0 24px;
}

/* ── Login Page ───────────────────────────────────────────── */
.login-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 24px;
    position: relative;
    z-index: 1;
}

.login-card {
    width: 100%;
    max-width: 420px;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-xl);
    padding: 40px 36px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(20px);
    -webkit-backdrop-filter: blur(20px);
    animation: cardEnter 0.6s var(--ease) forwards;
}

.login-logo {
    width: 52px;
    height: 52px;
    border-radius: var(--radius-md);
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    display: grid;
    place-items: center;
    font-size: 24px;
    margin: 0 auto 20px;
    box-shadow: 0 8px 24px rgba(99, 102, 241, 0.4);
}

.login-title {
    text-align: center;
    font-size: 26px;
    font-weight: 700;
    letter-spacing: -0.5px;
    margin-bottom: 6px;
    background: linear-gradient(132deg, var(--text) 0%, var(--accent) 60%, var(--accent2) 100%);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
}

.login-subtitle {
    text-align: center;
    font-size: 14px;
    color: var(--text2);
    margin-bottom: 32px;
}

/* ── Cards / Sections ─────────────────────────────────────── */
.section {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius-lg);
    padding: 28px;
    margin-bottom: 24px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    animation: cardEnter 0.5s var(--ease) forwards;
    opacity: 0;
    transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}

.section:hover {
    border-color: var(--border2);
}

.section:nth-child(1) { animation-delay: 0.06s; }
.section:nth-child(2) { animation-delay: 0.12s; }
.section:nth-child(3) { animation-delay: 0.18s; }
.section:nth-child(4) { animation-delay: 0.24s; }

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
    margin-bottom: 20px;
}

.section-title {
    font-size: 18px;
    font-weight: 600;
    color: var(--text);
    letter-spacing: -0.3px;
    display: flex;
    align-items: center;
    gap: 10px;
}

.section-title::before {
    content: "";
    display: block;
    width: 3px;
    height: 18px;
    border-radius: 2px;
    background: linear-gradient(180deg, var(--accent), var(--accent2));
}

/* ── Alerts ───────────────────────────────────────────────── */
.alert {
    padding: 14px 18px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    font-size: 14px;
    border-left: 3px solid;
    animation: slideInDown 0.4s var(--ease) forwards;
}

.alert-success {
    background: var(--alert-success-bg);
    color: var(--alert-success-text);
    border-left-color: var(--green);
}

.alert-error {
    background: var(--alert-error-bg);
    color: var(--alert-error-text);
    border-left-color: var(--red);
}

.info-box {
    background: var(--alert-info-bg);
    color: var(--alert-info-text);
    border-left: 3px solid var(--blue);
    padding: 14px 18px;
    border-radius: var(--radius-md);
    margin-bottom: 20px;
    font-size: 14px;
}

/* ── Forms ────────────────────────────────────────────────── */
.form-group {
    margin-bottom: 20px;
}

label {
    display: block;
    margin-bottom: 6px;
    font-size: 13px;
    font-weight: 500;
    color: var(--text2);
}

input[type="text"],
input[type="password"],
input[type="file"],
select,
textarea {
    width: 100%;
    padding: 11px 14px;
    background: var(--bg-input);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 14px;
    color: var(--text);
    font-family: inherit;
    transition: border-color var(--fast) var(--ease), box-shadow var(--fast) var(--ease);
}

input[type="text"]:focus,
input[type="password"]:focus,
input[type="file"]:focus,
select:focus,
textarea:focus {
    outline: none;
    border-color: var(--accent);
    box-shadow: 0 0 0 3px rgba(99, 102, 241, 0.15);
}

small {
    display: block;
    margin-top: 4px;
    font-size: 12px;
    color: var(--text3);
}

.search-bar {
    display: flex;
    gap: 8px;
    align-items: center;
    flex-wrap: wrap;
}

.search-bar input {
    min-width: 220px;
    flex: 1;
}

/* ── Buttons ───────────────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 9px 18px;
    background: linear-gradient(135deg, var(--accent), var(--accent2));
    color: #fff;
    border: none;
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 600;
    font-family: inherit;
    cursor: pointer;
    text-decoration: none;
    transition: transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease), opacity var(--fast);
    white-space: nowrap;
}

.btn:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 20px rgba(99, 102, 241, 0.4);
}

.btn:active {
    transform: translateY(0);
}

.btn-ghost {
    background: transparent;
    color: var(--text);
    border: 1px solid var(--border);
    box-shadow: none;
}

.btn-ghost:hover {
    background: var(--bg-hover);
    border-color: var(--border2);
    box-shadow: none;
    transform: translateY(-1px);
}

.btn-danger {
    background: linear-gradient(135deg, #ef4444, #dc2626);
}

.btn-danger:hover {
    box-shadow: 0 6px 20px rgba(239, 68, 68, 0.4);
}

.btn-warning {
    background: linear-gradient(135deg, #f59e0b, #d97706);
    color: #1a1f36;
}

.btn-warning:hover {
    box-shadow: 0 6px 20px rgba(245, 158, 11, 0.4);
}

.btn-teal {
    background: linear-gradient(135deg, var(--teal), #0d9488);
}

.btn-teal:hover {
    box-shadow: 0 6px 20px rgba(20, 184, 166, 0.4);
}

.btn-green {
    background: linear-gradient(135deg, var(--green), #059669);
}

.btn-green:hover {
    box-shadow: 0 6px 20px rgba(16, 185, 129, 0.4);
}

.btn-muted {
    background: var(--bg-item);
    color: var(--text2);
    border: 1px solid var(--border);
    box-shadow: none;
}

.btn-muted:hover {
    background: var(--bg-hover);
    box-shadow: none;
}

.btn-small {
    padding: 6px 12px;
    font-size: 12px;
}

.btn-full {
    width: 100%;
    padding: 13px;
    font-size: 15px;
    border-radius: var(--radius-md);
}

.logout-btn {
    padding: 7px 16px;
    background: transparent;
    color: var(--text2);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: all var(--fast) var(--ease);
    cursor: pointer;
    font-family: inherit;
}

.logout-btn:hover {
    background: var(--bg-hover);
    color: var(--text);
    border-color: var(--border2);
}

/* ── Tables ───────────────────────────────────────────────── */
.table-wrap {
    overflow-x: auto;
    border-radius: var(--radius-md);
    border: 1px solid var(--border);
}

table {
    width: 100%;
    border-collapse: collapse;
    font-size: 14px;
}

th {
    background: var(--bg-item);
    color: var(--text2);
    font-weight: 600;
    font-size: 12px;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 12px 16px;
    text-align: left;
    border-bottom: 1px solid var(--border);
}

td {
    padding: 13px 16px;
    border-bottom: 1px solid var(--border);
    color: var(--text);
    vertical-align: middle;
}

tr:last-child td {
    border-bottom: none;
}

tbody tr {
    transition: background var(--fast) var(--ease);
    animation: rowSlide 0.35s var(--ease) forwards;
    opacity: 0;
}

tbody tr:hover {
    background: var(--bg-hover);
}

tbody tr:nth-child(1) { animation-delay: 0.04s; }
tbody tr:nth-child(2) { animation-delay: 0.08s; }
tbody tr:nth-child(3) { animation-delay: 0.12s; }
tbody tr:nth-child(4) { animation-delay: 0.16s; }
tbody tr:nth-child(5) { animation-delay: 0.20s; }

.td-actions {
    display: flex;
    gap: 6px;
    flex-wrap: wrap;
}

.empty-state {
    text-align: center;
    padding: 40px 20px;
    color: var(--text3);
    font-size: 14px;
}

/* ── Badges ───────────────────────────────────────────────── */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 11px;
    font-weight: 600;
    letter-spacing: 0.3px;
    text-transform: uppercase;
}

.badge-admin {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
    border: 1px solid rgba(239, 68, 68, 0.3);
}

.badge-developer {
    background: rgba(16, 185, 129, 0.15);
    color: #6ee7b7;
    border: 1px solid rgba(16, 185, 129, 0.3);
}

body.theme-light .badge-admin {
    color: #991b1b;
    background: #fee2e2;
    border-color: #fca5a5;
}

body.theme-light .badge-developer {
    color: #065f46;
    background: #d1fae5;
    border-color: #6ee7b7;
}

/* ── Modal ────────────────────────────────────────────────── */
.modal {
    display: none;
    position: fixed;
    inset: 0;
    z-index: 200;
    background: rgba(0, 0, 0, 0.6);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    align-items: center;
    justify-content: center;
    padding: 20px;
}

.modal.is-open {
    display: flex;
    animation: fadeIn 0.2s var(--ease);
}

.modal-content {
    background: var(--bg-card);
    border: 1px solid var(--border2);
    border-radius: var(--radius-lg);
    padding: 32px;
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow);
    animation: modalIn 0.35s var(--ease) forwards;
    position: relative;
}

.modal-content h2 {
    font-size: 18px;
    font-weight: 600;
    margin-bottom: 24px;
    color: var(--text);
}

.modal-close {
    position: absolute;
    top: 16px;
    right: 20px;
    background: none;
    border: none;
    font-size: 22px;
    color: var(--text3);
    cursor: pointer;
    line-height: 1;
    padding: 4px;
    transition: color var(--fast);
}

.modal-close:hover {
    color: var(--text);
}

/* ── Theme Toggle ─────────────────────────────────────────── */
.theme-toggle {
    position: fixed;
    bottom: 24px;
    right: 24px;
    z-index: 150;
    width: 48px;
    height: 48px;
    border-radius: 50%;
    background: var(--bg-card);
    border: 1px solid var(--border);
    color: var(--text);
    cursor: pointer;
    display: grid;
    place-items: center;
    font-size: 18px;
    box-shadow: var(--shadow);
    backdrop-filter: blur(12px);
    -webkit-backdrop-filter: blur(12px);
    transition: transform var(--fast) var(--ease), box-shadow var(--fast) var(--ease), border-color var(--fast);
}

.theme-toggle:hover {
    transform: scale(1.08) rotate(15deg);
    border-color: var(--accent);
    box-shadow: 0 6px 24px rgba(99, 102, 241, 0.3);
}

.theme-toggle:active {
    transform: scale(0.95);
}

/* ── Animations ───────────────────────────────────────────── */
@keyframes cardEnter {
    from { opacity: 0; transform: translateY(20px); }
    to   { opacity: 1; transform: none; }
}

@keyframes rowSlide {
    from { opacity: 0; transform: translateX(-10px); }
    to   { opacity: 1; transform: none; }
}

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

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

@keyframes modalIn {
    from { opacity: 0; transform: scale(0.95) translateY(10px); }
    to   { opacity: 1; transform: none; }
}

/* ── Responsive ───────────────────────────────────────────── */
@media (max-width: 640px) {
    .topbar-inner {
        padding: 0 16px;
    }

    .topbar-user {
        display: none;
    }

    .section {
        padding: 20px 16px;
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .search-bar {
        width: 100%;
    }

    .search-bar input {
        min-width: unset;
    }

    .login-card {
        padding: 32px 24px;
    }

    .td-actions {
        flex-direction: column;
    }
}

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