/* ========================================
   MyAdmin - Light/Dark Theme
   ======================================== */

:root {
    --bg: #f5f7fa;
    --bg-card: #ffffff;
    --bg-sidebar: #1e293b;
    --bg-sidebar-hover: #334155;
    --bg-input: #ffffff;
    --text: #1e293b;
    --text-muted: #64748b;
    --text-sidebar: #cbd5e1;
    --text-sidebar-active: #ffffff;
    --border: #e2e8f0;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --success: #10b981;
    --danger: #ef4444;
    --warning: #f59e0b;
    --shadow: 0 1px 3px rgba(0,0,0,.08);
    --shadow-lg: 0 4px 12px rgba(0,0,0,.1);
    --radius: 8px;
}

[data-theme="dark"] {
    --bg: #0f172a;
    --bg-card: #1e293b;
    --bg-sidebar: #0f172a;
    --bg-sidebar-hover: #1e293b;
    --bg-input: #334155;
    --text: #e2e8f0;
    --text-muted: #94a3b8;
    --border: #334155;
    --shadow: 0 1px 3px rgba(0,0,0,.3);
    --shadow-lg: 0 4px 12px rgba(0,0,0,.4);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.6;
    min-height: 100vh;
}

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

/* ---- Layout ---- */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: 240px;
    background: var(--bg-sidebar);
    padding: 1.25rem 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    overflow-y: auto;
    z-index: 100;
    transition: transform .2s;
}

.sidebar-brand {
    padding: 0 1.25rem 1.5rem;
    font-size: 1.25rem;
    font-weight: 700;
    color: #fff;
    display: flex;
    align-items: center;
    gap: .5rem;
}

.sidebar-brand svg { flex-shrink: 0; }

.sidebar-nav { list-style: none; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .65rem 1.25rem;
    color: var(--text-sidebar);
    font-size: .875rem;
    transition: background .15s, color .15s;
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover,
.sidebar-nav a.active {
    background: var(--bg-sidebar-hover);
    color: var(--text-sidebar-active);
    border-left-color: var(--primary);
}

.sidebar-section {
    padding: 1rem 1.25rem .4rem;
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: #64748b;
}

.main-content {
    flex: 1;
    margin-left: 240px;
    padding: 1.5rem 2rem;
    min-width: 0;
}

/* ---- Top Bar ---- */
.topbar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1.5rem;
}

.topbar h1 {
    font-size: 1.5rem;
    font-weight: 700;
}

.topbar-actions {
    display: flex;
    align-items: center;
    gap: .75rem;
}

/* ---- Theme Toggle ---- */
.theme-toggle {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 50%;
    width: 36px; height: 36px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    color: var(--text);
    font-size: 1.1rem;
    transition: background .15s;
    box-shadow: var(--shadow);
}
.theme-toggle:hover { background: var(--border); }
.theme-toggle .icon-sun { display: none; }
[data-theme="dark"] .theme-toggle .icon-moon { display: none; }
[data-theme="dark"] .theme-toggle .icon-sun { display: block; }

/* ---- Cards ---- */
.card {
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
}

.card-body { padding: 1.25rem; }

.stat-card {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: 1.25rem;
}

.stat-icon {
    width: 48px; height: 48px;
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.3rem;
    flex-shrink: 0;
}

.stat-icon.blue { background: #dbeafe; color: #2563eb; }
.stat-icon.green { background: #d1fae5; color: #059669; }
.stat-icon.amber { background: #fef3c7; color: #d97706; }
.stat-icon.purple { background: #ede9fe; color: #7c3aed; }

[data-theme="dark"] .stat-icon.blue { background: #1e3a5f; }
[data-theme="dark"] .stat-icon.green { background: #064e3b; }
[data-theme="dark"] .stat-icon.amber { background: #451a03; }
[data-theme="dark"] .stat-icon.purple { background: #2e1065; }

.stat-info h3 {
    font-size: 1.5rem;
    font-weight: 700;
    line-height: 1.2;
}

.stat-info p {
    font-size: .8rem;
    color: var(--text-muted);
    margin-top: 2px;
}

/* ---- Grid ---- */
.grid { display: grid; gap: 1rem; }
.grid-2 { grid-template-columns: repeat(2, 1fr); }
.grid-3 { grid-template-columns: repeat(3, 1fr); }
.grid-4 { grid-template-columns: repeat(4, 1fr); }

@media (max-width: 1024px) {
    .grid-4 { grid-template-columns: repeat(2, 1fr); }
    .grid-3 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 640px) {
    .grid-4, .grid-3, .grid-2 { grid-template-columns: 1fr; }
    .main-content { padding: 1rem; }

    /* Topbar stacks */
    .topbar { flex-wrap: wrap; gap: .5rem; }
    .topbar h1 { font-size: 1.15rem; }

    /* Search bar full width */
    .search-bar .form-input,
    .search-bar select.form-input { max-width: 100%; flex: 1 1 100%; }

    /* Table min-width for scroll */
    table { min-width: 600px; }

    /* Auth page less padding */
    .auth-page { padding: 1rem; }
    .auth-card .card-body { padding: 1.25rem; }
    .auth-header h1 { font-size: 1.25rem; }

    /* Pagination wrap */
    .pagination { flex-wrap: wrap; }
}

/* ---- Table ---- */
.table-wrap { overflow-x: auto; }

table {
    width: 100%;
    border-collapse: collapse;
    font-size: .875rem;
}

th {
    text-align: left;
    padding: .75rem 1rem;
    font-weight: 600;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .03em;
    color: var(--text-muted);
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

td {
    padding: .65rem 1rem;
    border-bottom: 1px solid var(--border);
    vertical-align: middle;
}

tr:hover td { background: var(--bg); }
[data-theme="dark"] tr:hover td { background: #0f172a; }

/* ---- Badges ---- */
.badge {
    display: inline-block;
    padding: .15rem .55rem;
    border-radius: 50px;
    font-size: .72rem;
    font-weight: 600;
    line-height: 1.5;
}

.badge-green { background: #d1fae5; color: #065f46; }
.badge-red { background: #fee2e2; color: #991b1b; }
.badge-blue { background: #dbeafe; color: #1e40af; }
.badge-gray { background: #f1f5f9; color: #475569; }

[data-theme="dark"] .badge-green { background: #064e3b; color: #6ee7b7; }
[data-theme="dark"] .badge-red { background: #450a0a; color: #fca5a5; }
[data-theme="dark"] .badge-blue { background: #1e3a5f; color: #93c5fd; }
[data-theme="dark"] .badge-gray { background: #334155; color: #94a3b8; }

/* ---- Buttons ---- */
.btn {
    display: inline-flex;
    align-items: center;
    gap: .4rem;
    padding: .5rem 1rem;
    border-radius: 6px;
    font-size: .8125rem;
    font-weight: 500;
    border: 1px solid transparent;
    cursor: pointer;
    transition: background .15s, box-shadow .15s;
    text-decoration: none;
    line-height: 1.4;
}

.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-hover); color: #fff; }
.btn-success { background: var(--success); color: #fff; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { background: #dc2626; color: #fff; }
.btn-outline {
    background: transparent;
    border-color: var(--border);
    color: var(--text);
}
.btn-outline:hover { background: var(--bg); }
.btn-sm { padding: .3rem .65rem; font-size: .75rem; }

/* ---- Forms ---- */
.form-group { margin-bottom: 1rem; }

.form-label {
    display: block;
    font-size: .8125rem;
    font-weight: 500;
    margin-bottom: .35rem;
    color: var(--text);
}

.form-input {
    width: 100%;
    padding: .55rem .75rem;
    border: 1px solid var(--border);
    border-radius: 6px;
    font-size: .875rem;
    background: var(--bg-input);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
}

.form-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(59,130,246,.15);
}

.form-check {
    display: flex;
    align-items: center;
    gap: .5rem;
    font-size: .875rem;
}

.form-check input[type="checkbox"] {
    width: 16px; height: 16px;
    accent-color: var(--primary);
}

select.form-input {
    appearance: auto;
}

.input-password-wrap {
    position: relative;
}

.input-password-wrap .form-input {
    padding-right: 2.5rem;
}

.password-toggle {
    position: absolute;
    right: .5rem;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--text-muted);
    padding: .25rem;
    display: flex;
    align-items: center;
}

.password-toggle:hover {
    color: var(--text);
}

/* ---- Messages ---- */
.messages { list-style: none; margin-bottom: 1rem; }
.messages li {
    padding: .75rem 1rem;
    border-radius: 6px;
    font-size: .875rem;
    margin-bottom: .5rem;
}
.messages .success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.messages .error { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.messages .info { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }
.messages .warning { background: #fef3c7; color: #92400e; border: 1px solid #fde68a; }

[data-theme="dark"] .messages .success { background: #064e3b; color: #6ee7b7; border-color: #065f46; }
[data-theme="dark"] .messages .error { background: #450a0a; color: #fca5a5; border-color: #7f1d1d; }
[data-theme="dark"] .messages .info { background: #1e3a5f; color: #93c5fd; border-color: #1e40af; }
[data-theme="dark"] .messages .warning { background: #451a03; color: #fcd34d; border-color: #92400e; }

/* ---- Auth Pages (login, register, profile) ---- */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 2rem;
    background: var(--bg);
}

.auth-card {
    width: 100%;
    max-width: 420px;
}

.auth-card .card-body { padding: 2rem; }

.auth-header {
    text-align: center;
    margin-bottom: 1.5rem;
}

.auth-header h1 {
    font-size: 1.5rem;
    font-weight: 700;
    margin-bottom: .25rem;
}

.auth-header p {
    color: var(--text-muted);
    font-size: .875rem;
}

.auth-logo {
    width: 44px; height: 44px;
    background: var(--primary);
    border-radius: 12px;
    display: flex;
    align-items: center;
    justify-content: center;
    margin: 0 auto 1rem;
    color: #fff;
    font-size: 1.3rem;
    font-weight: 700;
}

.auth-footer {
    text-align: center;
    margin-top: 1.25rem;
    font-size: .8125rem;
    color: var(--text-muted);
}

.auth-footer a { font-weight: 500; }

.auth-theme-toggle {
    position: fixed;
    top: 1rem;
    right: 1rem;
}

/* ---- Pagination ---- */
.pagination {
    display: flex;
    gap: .25rem;
    list-style: none;
    margin-top: 1rem;
    align-items: center;
}

.pagination a,
.pagination span {
    padding: .4rem .7rem;
    border-radius: 6px;
    font-size: .8125rem;
    border: 1px solid var(--border);
    color: var(--text);
}

.pagination a:hover { background: var(--bg); }
.pagination .current {
    background: var(--primary);
    color: #fff;
    border-color: var(--primary);
}

/* ---- Utility ---- */
.text-muted { color: var(--text-muted); }
.text-sm { font-size: .8125rem; }
.mt-1 { margin-top: 1rem; }
.mb-1 { margin-bottom: 1rem; }
.flex { display: flex; }
.items-center { align-items: center; }
.gap-1 { gap: .5rem; }
.gap-2 { gap: 1rem; }
.justify-between { justify-content: space-between; }

/* ---- Avatar ---- */
.avatar {
    width: 32px; height: 32px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: .75rem;
    font-weight: 600;
    color: #fff;
    background: var(--primary);
    flex-shrink: 0;
}

/* ---- Section titles inside tables ---- */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 1rem;
}

.section-header h2 {
    font-size: 1.1rem;
    font-weight: 600;
}

/* ---- Search ---- */
.search-bar {
    display: flex;
    gap: .5rem;
    margin-bottom: 1rem;
    flex-wrap: wrap;
}

.search-bar .form-input { max-width: 280px; }
.search-bar select.form-input { max-width: 160px; }

/* ---- Sidebar Backdrop ---- */
.sidebar-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.5);
    z-index: 99;
}

/* ---- Mobile toggle ---- */
.mobile-toggle {
    display: none;
    background: var(--bg-card);
    border: 1px solid var(--border);
    border-radius: 6px;
    padding: .5rem;
    cursor: pointer;
    color: var(--text);
    font-size: 1.2rem;
}

@media (max-width: 768px) {
    .sidebar { transform: translateX(-100%); }
    .sidebar.open { transform: translateX(0); }
    .main-content { margin-left: 0; padding: 1.25rem; }
    .mobile-toggle { display: flex; }
    .sidebar-backdrop.active { display: block; }
    .grid-3 { grid-template-columns: 1fr; }
}

