:root{
    --bg: #f4f6f8;
    --surface: #ffffff;
    --surface-2: #f8fafc;
    --border: #dbe2ea;
    --text: #1f2937;
    --muted: #6b7280;
    --primary: #3aa6e8;
    --primary-dark: #248bcb;
    --danger: #ef5b52;
    --danger-dark: #df4a42;
    --success: #37b37e;
    --shadow: 0 12px 32px rgba(15, 23, 42, 0.08);
    --radius: 18px;
}

/* Dark mode overrides */
body.dark-mode{
    --bg: #0f1720;
    --surface: #18212b;
    --surface-2: #1d2833;
    --border: #2b3947;
    --text: #e5edf5;
    --muted: #9aa8b7;
    --primary: #4db7f2;
    --primary-dark: #309adb;
    --danger: #f06a61;
    --danger-dark: #dc5148;
    --success: #42c48d;
    --shadow: 0 14px 32px rgba(0, 0, 0, 0.35);
}

*{ box-sizing:border-box; }

html, body{
    margin:0;
    padding:0;
    min-height:100%;
    font-family: Arial, sans-serif;
    background: linear-gradient(180deg, var(--surface-2) 0%, var(--bg) 100%);
    color: var(--text);
}

body{
    min-height:100vh;
}

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

a:hover{ text-decoration:underline; }

.center-page{
    min-height:100vh;
    display:flex;
    justify-content:center;
    align-items:center;
    padding:32px 16px;
}

.auth-shell,
.dashboard-shell,
.admin-shell{
    width:min(1100px, 100%);
    margin:0 auto;
    padding:32px 18px;
}

.dashboard-shell,
.admin-shell{
    min-height:100vh;
}

/* New auth-page layout */
body.auth-page{
    min-height: 100vh;
}

body.auth-page .auth-shell{
    min-height: 100vh;
    width: 100%;
    max-width: 100%;
    display:flex;
    flex-direction:column;
    justify-content:center;
    align-items:center;
    padding:32px 20px;
}

.auth-brand{
    text-align:center;
    font-size:20px;
    font-weight:700;
    letter-spacing:0.4px;
    margin-bottom:22px;
    color: var(--primary-dark);
}

.auth-brand span{
    color: var(--text);
    opacity: 0.75;
    font-weight:500;
}

.auth-panel{
    width:min(460px, 100%);
    background: rgba(255,255,255,0.92);
    border:1px solid var(--border);
    border-radius:22px;
    box-shadow: var(--shadow);
    padding:30px 28px 26px;
    text-align:center;
}

.auth-panel h1{
    margin:0 0 10px;
    font-size:24px;
    font-weight:700;
}

.auth-subtitle{
    text-align:center;
    color:var(--muted);
    margin:0 0 24px;
    font-size:18px;
    line-height:1.4;
}

.auth-form{
    display:flex;
    flex-direction:column;
    gap:14px;
}

/* Input groups for the modern auth look */
.input-group{
    display:flex;
    align-items:center;
    height:58px;
    padding:0 14px;
    border:1px solid var(--border);
    border-radius:12px;
    background:#f9fbfd;
    transition:0.15s ease;
}

.input-group:focus-within{
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(58,166,232,0.12);
}

.input-icon{
    width:22px;
    min-width:22px;
    margin-right:12px;
    display:flex;
    align-items:center;
    justify-content:center;
    font-size:16px;
    line-height:1;
    opacity:0.75;
}

.input-group input{
    width:100%;
    border:none;
    outline:none;
    background:transparent;
    margin:0;
    padding:0;
    font-size:16px;
    color:var(--text);
    box-shadow:none;
    border-radius:0;
}

.input-group input::placeholder{
    color:var(--muted);
}

/* Legacy card/auth layout kept for other pages */
.card{
    width:min(460px, 100%);
    margin:0 auto;
    background: rgba(255,255,255,0.88);
    backdrop-filter: blur(8px);
    border:1px solid var(--border);
    border-radius: 22px;
    box-shadow: var(--shadow);
    overflow:hidden;
}

.brand{
    text-align:center;
    font-size:20px;
    font-weight:700;
    letter-spacing:0.4px;
    padding:22px 24px 12px;
}

.brand-logo{
    max-width: 260px;
    width: 100%;
    height: auto;
    display: inline-block;
}

.brand .accent{ color: var(--primary-dark); }

.auth-body{
    margin: 0 18px 18px;
    background: var(--surface);
    border:1px solid var(--border);
    border-radius: 18px;
    padding: 28px 26px 26px;
}

.auth-title{
    text-align:center;
    font-size:24px;
    margin:0 0 10px;
    font-weight:700;
}

/* Keep subtitle class consistent */
.auth-title + .auth-subtitle{
    margin-top: 0;
}

.form-group{ margin-bottom:14px; }

.input-label{
    display:block;
    font-size:14px;
    color:var(--muted);
    margin-bottom:6px;
}

/* Important: do NOT style auth-page input-group inputs here */
.input,
select,
input:not(.input-group input){
    width:100%;
    padding:14px 16px;
    border-radius:12px;
    border:1px solid var(--border);
    background:#f9fbfd;
    color:var(--text);
    outline:none;
    font-size:16px;
}

.input:focus,
select:focus,
input:not(.input-group input):focus{
    border-color: var(--primary);
    box-shadow: 0 0 0 4px rgba(58,166,232,0.12);
}

/* Important: do NOT force all buttons when using custom auth buttons */
.btn,
button:not(.primary-btn){
    width:100%;
    border:none;
    border-radius:12px;
    padding:15px 18px;
    font-size:16px;
    font-weight:700;
    cursor:pointer;
    transition:0.15s ease;
}

.btn-primary,
button:not(.primary-btn){
    background: linear-gradient(180deg, #53b9f4 0%, #2e9ddd 100%);
    color:white;
}

.btn-primary:hover,
button:not(.primary-btn):hover{
    background: linear-gradient(180deg, #4ab3f0 0%, #278fcf 100%);
}

.primary-btn{
    width:100%;
    margin-top:10px;
    height:52px;
    border:none;
    border-radius:12px;
    background: linear-gradient(180deg, #53b9f4 0%, #2e9ddd 100%);
    color:white;
    font-size:18px;
    font-weight:700;
    cursor:pointer;
    transition:0.15s ease;
}

.primary-btn:hover{
    background: linear-gradient(180deg, #4ab3f0 0%, #278fcf 100%);
}

.btn-secondary{
    background:#f6f8fb;
    color:var(--text);
    border:1px solid var(--border);
}

.btn-secondary:hover{ background:#eef3f8; }

.btn-danger{
    background: linear-gradient(180deg, #f16d64 0%, #e35148 100%);
    color:white;
}

.btn-danger:hover{ background: linear-gradient(180deg, #eb655c 0%, #d94840 100%); }

.auth-actions{
    display:flex;
    flex-direction:column;
    gap:12px;
    margin-top:22px;
}

.auth-footer{
    display:flex;
    justify-content:space-between;
    gap:12px;
    flex-wrap:wrap;
    margin-top:22px;
    color:var(--muted);
    font-size:14px;
}

.auth-footer-text{
    margin:20px 0 0;
    color:var(--muted);
    font-size:15px;
}

.auth-footer-text a{
    color: var(--primary-dark);
    font-weight:500;
}

.auth-links{
    margin-top:24px;
    font-size:14px;
    color:var(--muted);
    display:flex;
    justify-content:center;
    gap:10px;
    flex-wrap:wrap;
}

.auth-links a{
    color:var(--muted);
}

.error{ color:#d63d3d; margin-top:14px; }
.success{ color:var(--success); margin-top:14px; }

.alert{
    margin-top:16px;
    padding:12px 14px;
    border-radius:8px;
    font-size:14px;
    text-align:left;
}

.error-alert{
    background:#ffe2e2;
    color:#b42318;
    border:1px solid #f5b5b5;
}

.success-alert{
    background:#e7f8ec;
    color:#16794c;
    border:1px solid #b7e3c5;
}

.app-panel{
    background: rgba(255,255,255,0.9);
    border:1px solid var(--border);
    border-radius:22px;
    box-shadow: var(--shadow);
    overflow:hidden;
}

.panel-header{
    text-align:center;
    padding:28px 24px 16px;
}

.panel-title{
    font-size:26px;
    font-weight:800;
    margin:0;
}

.panel-subtitle{
    color:var(--muted);
    margin:8px 0 0;
}

.panel-content{
    padding: 0 18px 18px;
}

.grid{
    display:grid;
    grid-template-columns: repeat(12, 1fr);
    gap:16px;
}

.stat-card,
.news-card,
.quick-card,
.table-card{
    background:var(--surface);
    border:1px solid var(--border);
    border-radius:18px;
    padding:18px;
}

.stat-card h3,
.news-card h3,
.quick-card h3,
.table-card h3{
    margin:0 0 12px;
    font-size:16px;
}

.stat-row{
    display:flex;
    align-items:center;
    justify-content:space-between;
    padding:14px 0;
    border-top:1px solid #edf1f5;
}

.stat-row:first-of-type{ border-top:none; padding-top:0; }
.badge{
    display:inline-flex;
    align-items:center;
    padding:6px 10px;
    border-radius:999px;
    font-size:13px;
    font-weight:700;
    background:#ebf8f2;
    color:#25875d;
}

.badge.blue{ background:#eaf6fd; color:#1974a8; }
.badge.red{ background:#feeceb; color:#c33d36; }

.action-row{
    display:grid;
    grid-template-columns:1fr 1fr;
    gap:14px;
}

.table-wrap{ width:100%; overflow-x:auto; }

table{
    width:100%;
    border-collapse:collapse;
    table-layout:fixed;
    background:var(--surface);
}

th, td{
    border:1px solid var(--border);
    padding:12px;
    text-align:left;
    vertical-align:top;
    word-break:break-word;
    overflow-wrap:anywhere;
}

th{ background:#f7fafc; }

.actions{
    display:flex;
    flex-direction:column;
    gap:8px;
}

body.dark-mode .card,
body.dark-mode .auth-panel,
body.dark-mode .app-panel,
body.dark-mode .stat-card,
body.dark-mode .news-card,
body.dark-mode .quick-card,
body.dark-mode .table-card,
body.dark-mode .auth-body{
    background: var(--surface);
    color: var(--text);
    border-color: var(--border);
}

body.dark-mode table{
    background: var(--surface);
}

body.dark-mode th{
    background: #1e2a35;
}

body.dark-mode .input-group{
    background: #1b2631;
    border-color: var(--border);
}

body.dark-mode .input-group input{
    color: var(--text);
}

body.dark-mode .input-group input::placeholder{
    color: var(--muted);
}

body.dark-mode .input,
body.dark-mode select,
body.dark-mode input:not(.input-group input){
    background: #1b2631;
    color: var(--text);
    border-color: var(--border);
}

body.dark-mode .btn-secondary{
    background: #1d2833;
    color: var(--text);
    border-color: var(--border);
}

body.dark-mode .btn-secondary:hover{
    background: #23313e;
}

.theme-toggle{
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    border-radius: 12px;
    padding: 10px 14px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 700;
    transition: 0.15s ease;
}

.theme-toggle:hover{
    background: var(--surface-2);
}

.theme-toggle-wrap{
    display: flex;
    justify-content: flex-end;
    margin-bottom: 14px;
}

.actions form{ margin:0; }
.actions .btn{ padding:10px 12px; font-size:14px; }

.empty{ color:var(--muted); }
.muted{ color:var(--muted); }

.dashboard-main{ grid-column: span 8; }
.dashboard-side{ grid-column: span 4; }
.admin-main{ grid-column: span 12; }

@media (max-width: 900px){
    .dashboard-main,
    .dashboard-side,
    .admin-main{ grid-column: span 12; }

    .action-row{ grid-template-columns:1fr; }
}