/* ==========================================================================
 * Adminix — Generic Admin Dashboard Template
 * A domain-neutral, reusable backend dashboard UI.
 *
 * HOW TO REBRAND:
 *   - Change the brand color by editing --primary / --accent below.
 *   - Everything else (surfaces, text, borders) is derived from semantic
 *     tokens, so light & dark themes stay consistent automatically.
 * ========================================================================= */

:root {
    /* --- Brand colors (change these to rebrand) --- */
    --primary: #4FA7E8;
    --primary-dark: #2F8AC9;
    --primary-light: #7BC1F0;
    --accent: #F9B233;
    --accent-dark: #E69915;

    /* --- Status colors --- */
    --success: #7BC67E;
    --success-dark: #5FA862;
    --danger: #E57373;
    --danger-dark: #C62828;
    --warning: #F9B233;
    --info: #4FA7E8;

    /* --- Semantic surfaces & text (light theme) --- */
    --bg: #F5FAFF;
    --surface: #FFFFFF;
    --surface-2: #F5FAFF;
    --soft: #EAF6FF;
    --text: #2F3E46;
    --muted: #6C757D;
    --muted-light: #A8B2BB;
    --border: #E6EEF5;

    /* --- Sidebar (kept independent of theme) --- */
    --sidebar-from: var(--primary);
    --sidebar-to: var(--primary-dark);

    --shadow-sm: 0 1px 2px rgba(47, 138, 201, 0.06);
    --shadow-md: 0 6px 16px rgba(47, 138, 201, 0.10);
    --radius: 0.75rem;
}

/* --- Dark theme overrides --- */
:root[data-theme="dark"] {
    --bg: #0F172A;
    --surface: #1B2637;
    --surface-2: #172033;
    --soft: rgba(79, 167, 232, 0.14);
    --text: #E6EDF5;
    --muted: #9FB0C3;
    --muted-light: #6B7C90;
    --border: #2A3A4F;

    --shadow-sm: 0 1px 2px rgba(0, 0, 0, 0.4);
    --shadow-md: 0 8px 24px rgba(0, 0, 0, 0.45);
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    font-family: "Plus Jakarta Sans", system-ui, sans-serif;
    background: var(--bg);
    color: var(--text);
    -webkit-font-smoothing: antialiased;
    transition: background 0.2s ease, color 0.2s ease;
}

a { color: inherit; }

/* ===== Sidebar ===== */
.app-sidebar {
    width: 270px;
    flex-shrink: 0;
    height: 100vh;
    position: sticky;
    top: 0;
    background: linear-gradient(180deg, var(--sidebar-from) 0%, var(--sidebar-to) 100%);
    display: flex;
    flex-direction: column;
    color: white;
    z-index: 40;
}
.sidebar-scroll::-webkit-scrollbar { width: 4px; }
.sidebar-scroll::-webkit-scrollbar-thumb {
    background: rgba(255, 255, 255, 0.2);
    border-radius: 4px;
}

.sidebar-link {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 0.6rem 0.875rem;
    border-radius: 0.5rem;
    color: rgba(255, 255, 255, 0.8);
    font-size: 14px;
    font-weight: 500;
    text-decoration: none;
    transition: all 150ms ease;
    cursor: pointer;
}
.sidebar-link:hover { background: rgba(255, 255, 255, 0.1); color: white; }
.sidebar-link.active {
    background: white;
    color: var(--primary-dark);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}

.sidebar-sublink {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    padding: 0.5rem 0.75rem 0.5rem 2.5rem;
    border-radius: 0.5rem;
    color: rgba(255, 255, 255, 0.65);
    font-size: 13px;
    font-weight: 500;
    text-decoration: none;
    transition: all 150ms ease;
}
.sidebar-sublink:hover { background: rgba(255, 255, 255, 0.1); color: white; }
.sidebar-sublink.active { background: rgba(255, 255, 255, 0.15); color: white; }

.sidebar-section-label {
    font-size: 11px;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: 0.12em;
    color: rgba(255, 255, 255, 0.5);
    padding: 0 1rem;
    margin: 1rem 0 0.5rem;
}

/* ===== Cards ===== */
.card {
    background: var(--surface);
    border-radius: var(--radius);
    border: 1px solid var(--border);
    box-shadow: var(--shadow-sm);
}
.stat-card { transition: all 200ms ease; }
.stat-card:hover { transform: translateY(-2px); box-shadow: var(--shadow-md); }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 0.375rem;
    padding: 0.5rem 1rem;
    border-radius: 0.5rem;
    font-weight: 600;
    font-size: 13px;
    cursor: pointer;
    border: none;
    transition: all 150ms ease;
    text-decoration: none;
    white-space: nowrap;
    font-family: inherit;
}
.btn-primary {
    background: var(--accent);
    color: white;
    box-shadow: 0 4px 14px rgba(249, 178, 51, 0.35);
}
.btn-primary:hover { background: var(--accent-dark); box-shadow: 0 6px 18px rgba(249, 178, 51, 0.4); }
.btn-blue { background: var(--primary); color: white; }
.btn-blue:hover { background: var(--primary-dark); }
.btn-outline { background: var(--surface); color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--soft); }
.btn-ghost { background: transparent; color: var(--muted); }
.btn-ghost:hover { background: var(--soft); color: var(--primary-dark); }
.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: var(--danger-dark); }
.btn-sm { padding: 0.375rem 0.75rem; font-size: 12px; }
.btn-lg { padding: 0.75rem 1.5rem; font-size: 14px; }
.btn:disabled { opacity: 0.6; cursor: not-allowed; }

/* ===== Inputs ===== */
.input {
    width: 100%;
    height: 2.5rem;
    padding: 0 0.875rem;
    background: var(--surface-2);
    border: 1px solid transparent;
    border-radius: 0.5rem;
    color: var(--text);
    font-size: 14px;
    font-family: inherit;
    outline: none;
    transition: all 150ms ease;
}
.input::placeholder { color: var(--muted-light); }
.input:focus {
    background: var(--surface);
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(79, 167, 232, 0.12);
}
.input-icon { position: relative; }
.input-icon > i {
    position: absolute;
    left: 0.875rem;
    top: 50%;
    transform: translateY(-50%);
    color: var(--muted-light);
    pointer-events: none;
}
.input-icon .input { padding-left: 2.5rem; }
.input-icon .input-trailing { right: 0.875rem; left: auto; pointer-events: auto; cursor: pointer; }
.input-icon .has-trailing { padding-right: 2.75rem; }

.field-label {
    display: block;
    font-size: 12px;
    font-weight: 600;
    color: var(--text);
    margin-bottom: 0.375rem;
}
.field-error { color: var(--danger-dark); font-size: 12px; margin: 0.375rem 0 0; min-height: 1em; }

textarea.input { height: auto; min-height: 6rem; padding: 0.625rem 0.875rem; resize: vertical; }
select.input {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%236C757D' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 0.875rem center;
    padding-right: 2.5rem;
}

/* ===== Tables ===== */
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table thead tr { background: var(--surface-2); }
.table th {
    padding: 0.875rem 1.25rem;
    text-align: left;
    font-size: 11px;
    font-weight: 700;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.08em;
}
.table td { padding: 0.875rem 1.25rem; border-top: 1px solid var(--border); }
.table tbody tr:hover { background: var(--soft); }

/* ===== Badges ===== */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.375rem;
    padding: 0.25rem 0.625rem;
    border-radius: 9999px;
    font-size: 11px;
    font-weight: 700;
    border: 1px solid;
}
.badge::before {
    content: "";
    display: inline-block;
    width: 0.375rem;
    height: 0.375rem;
    border-radius: 50%;
    background: currentColor;
}
.badge-danger { background: rgba(229, 115, 115, 0.12); color: var(--danger-dark); border-color: rgba(229, 115, 115, 0.25); }
.badge-warning { background: rgba(249, 178, 51, 0.15); color: var(--accent-dark); border-color: rgba(249, 178, 51, 0.3); }
.badge-success { background: rgba(123, 198, 126, 0.15); color: var(--success-dark); border-color: rgba(123, 198, 126, 0.3); }
.badge-info { background: rgba(79, 167, 232, 0.12); color: var(--primary-dark); border-color: rgba(79, 167, 232, 0.25); }
.badge-gray { background: var(--soft); color: var(--muted); border-color: var(--border); }
.badge-gray::before { background: var(--muted-light); }

/* ===== Page header ===== */
.page-title { font-size: 28px; font-weight: 800; color: var(--text); letter-spacing: -0.02em; line-height: 1.1; margin: 0; }
.page-subtitle { color: var(--muted); margin-top: 0.375rem; font-size: 14px; }

/* ===== Breadcrumb ===== */
.breadcrumb { display: flex; align-items: center; gap: 0.375rem; font-size: 12px; color: var(--muted); margin-bottom: 0.5rem; }
.breadcrumb a { color: var(--muted); text-decoration: none; }
.breadcrumb a:hover { color: var(--primary-dark); }
.breadcrumb-current { color: var(--text); font-weight: 500; }

/* ===== Topbar ===== */
.topbar {
    position: sticky;
    top: 0;
    z-index: 30;
    background: color-mix(in srgb, var(--surface) 92%, transparent);
    backdrop-filter: blur(12px);
    border-bottom: 1px solid var(--border);
    height: 64px;
    display: flex;
    align-items: center;
    padding: 0 1.75rem;
    gap: 0.75rem;
}
.icon-btn {
    width: 40px;
    height: 40px;
    border: none;
    background: transparent;
    border-radius: 0.5rem;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: var(--muted);
    cursor: pointer;
    transition: all 150ms ease;
    position: relative;
}
.icon-btn:hover { background: var(--soft); color: var(--primary-dark); }

/* ===== Dropdown ===== */
.dropdown { position: relative; }
.dropdown-menu {
    position: absolute;
    right: 0;
    top: calc(100% + 8px);
    min-width: 200px;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
    box-shadow: var(--shadow-md);
    padding: 0.375rem;
    display: none;
    z-index: 50;
}
.dropdown-menu.open { display: block; }
.dropdown-item {
    display: flex;
    align-items: center;
    gap: 0.625rem;
    padding: 0.55rem 0.75rem;
    border-radius: 0.5rem;
    font-size: 13px;
    font-weight: 500;
    color: var(--text);
    text-decoration: none;
    cursor: pointer;
}
.dropdown-item:hover { background: var(--soft); color: var(--primary-dark); }
.dropdown-divider { height: 1px; background: var(--border); margin: 0.375rem 0; }

/* ===== Avatar ===== */
.avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: var(--soft);
    color: var(--primary-dark);
    display: inline-flex; align-items: center; justify-content: center;
    font-size: 12px; font-weight: 700; flex-shrink: 0;
}
.avatar-blue { background: var(--primary); color: white; }

/* ===== Tabs ===== */
.tabs { display: inline-flex; background: var(--surface); border: 1px solid var(--border); border-radius: 0.75rem; padding: 0.375rem; gap: 0.25rem; flex-wrap: wrap; }
.tab {
    display: inline-flex; align-items: center; gap: 0.375rem;
    padding: 0.5rem 1rem; border-radius: 0.5rem;
    font-size: 13px; font-weight: 600; color: var(--muted);
    cursor: pointer; text-decoration: none; background: transparent;
    border: none; font-family: inherit; transition: all 150ms ease;
}
.tab:hover { background: var(--soft); color: var(--primary-dark); }
.tab.active { background: var(--primary); color: white; }

/* ===== Switch ===== */
.switch { position: relative; display: inline-block; width: 38px; height: 22px; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch-slider { position: absolute; cursor: pointer; inset: 0; background: #CBD5E1; border-radius: 9999px; transition: 0.2s; }
.switch-slider::before { content: ""; position: absolute; height: 16px; width: 16px; left: 3px; bottom: 3px; background: white; border-radius: 50%; transition: 0.2s; }
.switch input:checked + .switch-slider { background: var(--success); }
.switch input:checked + .switch-slider::before { transform: translateX(16px); }

/* ===== Progress bar ===== */
.progress { width: 100%; height: 6px; background: var(--border); border-radius: 9999px; overflow: hidden; }
.progress > div { height: 100%; background: var(--primary); border-radius: 9999px; }

/* ===== Toast ===== */
#toast-root { position: fixed; top: 1rem; right: 1rem; z-index: 100; display: flex; flex-direction: column; gap: 0.5rem; }
.toast {
    display: flex; align-items: center; gap: 0.625rem;
    background: var(--surface); border: 1px solid var(--border);
    border-left: 4px solid var(--primary);
    border-radius: 0.625rem; padding: 0.75rem 1rem;
    box-shadow: var(--shadow-md); font-size: 13px; font-weight: 500; color: var(--text);
    min-width: 240px; animation: toastIn 0.25s ease-out;
}
.toast.success { border-left-color: var(--success); }
.toast.error { border-left-color: var(--danger); }
.toast.warning { border-left-color: var(--accent); }
@keyframes toastIn { from { opacity: 0; transform: translateX(20px); } to { opacity: 1; transform: translateX(0); } }

/* ===== Footer ===== */
.app-footer {
    text-align: center; padding: 1rem;
    font-size: 12px; color: var(--muted);
    border-top: 1px solid var(--border);
    background: color-mix(in srgb, var(--surface) 40%, transparent);
}

/* ===== Animations ===== */
.fade-in { animation: fadeIn 0.35s ease-out forwards; }
@keyframes fadeIn { from { opacity: 0; transform: translateY(8px); } to { opacity: 1; transform: translateY(0); } }

/* ===== Mobile sidebar ===== */
@media (max-width: 1023px) {
    .app-sidebar { position: fixed; transform: translateX(-100%); transition: transform 0.3s ease; }
    .app-sidebar.open { transform: translateX(0); }
    .sidebar-backdrop { position: fixed; inset: 0; background: rgba(47, 62, 70, 0.4); backdrop-filter: blur(2px); z-index: 35; display: none; }
    .sidebar-backdrop.show { display: block; }
}

/* ===== Utilities ===== */
.flex { display: flex; }
.flex-1 { flex: 1; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-1 { gap: 0.25rem; }
.gap-2 { gap: 0.5rem; }
.gap-3 { gap: 0.75rem; }
.min-w-0 { min-width: 0; }
.relative { position: relative; }
.text-right { text-align: right; }
.text-muted { color: var(--muted); }
.cursor-pointer { cursor: pointer; }
.hidden { display: none; }
