/* ============================================================
   assets/css/style.css
   ระบบยืม-คืน Chromebook - สไตล์หลักของระบบ (โทนน้ำเงิน-ทอง)
   ============================================================ */

:root {
    --color-primary: #14203d;
    --color-primary-dark: #0b1526;
    --color-gold: #c9a227;
    --color-gold-dark: #a6841c;
    --color-gold-bg: #f8ecc4;

    --color-bg: #f4f6fb;
    --color-surface: #ffffff;
    --color-border: #e2e6ee;
    --color-text: #1f2430;
    --color-text-muted: #6b7280;

    --color-green: #16a34a;
    --color-green-bg: #dcfce7;
    --color-blue: #2563eb;
    --color-blue-bg: #dbeafe;
    --color-orange: #d97706;
    --color-orange-bg: #fef3c7;
    --color-red: #dc2626;
    --color-red-bg: #fee2e2;

    --radius: 10px;
    --shadow: 0 1px 3px rgba(16, 24, 40, 0.06), 0 1px 2px rgba(16, 24, 40, 0.04);
    --font: 'IBM Plex Sans Thai', 'Segoe UI', 'Sarabun', 'Prompt', -apple-system, sans-serif;
}

* { box-sizing: border-box; }

body {
    margin: 0;
    font-family: var(--font);
    background: var(--color-bg);
    color: var(--color-text);
    line-height: 1.5;
}

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

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

.sidebar {
    width: 240px;
    flex-shrink: 0;
    background: linear-gradient(180deg, #0f1a33, #14203d 55%, #0f1a33);
    color: #cfd8f0;
    display: flex;
    flex-direction: column;
    position: sticky;
    top: 0;
    height: 100vh;
    height: 100dvh;
    border-right: 3px solid var(--color-gold);
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 1.1rem;
    font-weight: 700;
    color: #fff;
    padding: 20px 18px;
    border-bottom: 1px solid rgba(201, 162, 39, 0.25);
}

.sidebar-brand-logo {
    width: 34px;
    height: 34px;
    border-radius: 50%;
    background: linear-gradient(160deg, #e0b93a, var(--color-gold));
    display: flex;
    align-items: center;
    justify-content: center;
    flex-shrink: 0;
    overflow: hidden;
    box-shadow: 0 0 0 2px rgba(201, 162, 39, 0.35);
}

.sidebar-brand-logo img {
    width: 100%;
    height: 100%;
    object-fit: cover;
    border-radius: 50%;
}

.sidebar-brand-logo .fallback-icon {
    font-size: 1.1rem;
    line-height: 1;
}

.sidebar-nav {
    display: flex;
    flex-direction: column;
    padding: 12px;
    gap: 4px;
    flex: 1;
    overflow-y: auto;
    min-height: 0;
}

.sidebar-nav a {
    color: #cfd8f0;
    text-decoration: none;
    padding: 11px 14px;
    border-radius: 8px;
    font-size: 0.95rem;
    transition: background 0.15s ease, color 0.15s ease;
    border-left: 3px solid transparent;
}

.sidebar-nav a:hover { background: rgba(201, 162, 39, 0.12); }

.sidebar-nav a.active {
    background: rgba(201, 162, 39, 0.16);
    color: #f5d976;
    font-weight: 600;
    border-left: 3px solid var(--color-gold);
}

.sidebar-footer {
    padding: 16px;
    border-top: 1px solid rgba(201, 162, 39, 0.25);
    flex-shrink: 0;
}

.user-chip {
    font-size: 0.85rem;
    margin-bottom: 10px;
    color: #e2e8f7;
}

.btn-logout {
    display: block;
    width: 100%;
    text-align: center;
    background: rgba(201, 162, 39, 0.14);
    color: #f5d976;
    padding: 8px;
    border-radius: 8px;
    font-size: 0.85rem;
    border: 1px solid rgba(201, 162, 39, 0.3);
}
.btn-logout:hover { background: rgba(201, 162, 39, 0.24); text-decoration: none; }

.content {
    flex: 1;
    padding: 28px 32px 60px;
    max-width: 1200px;
}

.page-title {
    font-size: 1.5rem;
    margin: 0 0 20px;
    color: #14203d;
    position: relative;
    padding-bottom: 10px;
}

.page-title::after {
    content: "";
    position: absolute;
    left: 0;
    bottom: 0;
    width: 56px;
    height: 3px;
    background: var(--color-gold);
    border-radius: 2px;
}

/* ---------------- Cards ---------------- */
.card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px 22px;
    margin-bottom: 22px;
    border-top: 3px solid var(--color-gold);
}

.card h2 {
    font-size: 1.05rem;
    margin: 0 0 14px;
    color: #14203d;
}

/* ---------------- Stat cards ---------------- */
.stat-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
    gap: 14px;
    margin-bottom: 22px;
}

.stat-card {
    background: var(--color-surface);
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 16px 18px;
    border-left: 4px solid var(--color-gold);
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.stat-card:hover {
    transform: translateY(-2px);
    box-shadow: 0 6px 16px rgba(20, 32, 61, 0.1);
}

.stat-value { font-size: 1.8rem; font-weight: 700; color: #14203d; }
.stat-label { font-size: 0.85rem; color: var(--color-text-muted); margin-top: 2px; }

.stat-green { border-left-color: var(--color-green); }
.stat-blue { border-left-color: var(--color-blue); }
.stat-orange { border-left-color: var(--color-orange); }
.stat-red { border-left-color: var(--color-red); }

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

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

thead th {
    text-align: left;
    background: #14203d;
    color: #f5d976;
    font-weight: 600;
    padding: 10px 12px;
    border-bottom: 2px solid var(--color-gold);
    white-space: nowrap;
}

tbody td {
    padding: 10px 12px;
    border-bottom: 1px solid var(--color-border);
}

tbody tr:hover { background: #faf6e8; }

.empty-row { text-align: center; color: var(--color-text-muted); padding: 24px !important; }

.row-overdue { background: #fff5f5; }

.row-actions { white-space: nowrap; }

.link-btn {
    background: none;
    border: none;
    color: var(--color-primary);
    cursor: pointer;
    font-size: 0.88rem;
    padding: 0;
    margin-right: 10px;
}
.link-btn:hover { text-decoration: underline; }
.link-danger { color: var(--color-red); }

/* ---------------- Badges ---------------- */
.badge {
    display: inline-block;
    padding: 3px 10px;
    border-radius: 999px;
    font-size: 0.78rem;
    font-weight: 600;
    text-transform: capitalize;
}

.badge-available, .badge-fixed, .badge-returned { background: var(--color-green-bg); color: var(--color-green); }
.badge-borrowed, .badge-in_progress { background: var(--color-blue-bg); color: var(--color-blue); }
.badge-repair, .badge-pending, .badge-repair-pending { background: var(--color-orange-bg); color: var(--color-orange); }
.badge-damaged, .badge-unfixable, .badge-repair-unfixable { background: var(--color-red-bg); color: var(--color-red); }
.badge-repair-fixed { background: var(--color-green-bg); color: var(--color-green); }
.badge-repair-in_progress { background: var(--color-blue-bg); color: var(--color-blue); }

/* ---------------- Toolbar ---------------- */
.toolbar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 16px;
}

.toolbar-form {
    display: flex;
    gap: 8px;
    flex-wrap: wrap;
    align-items: center;
}

.toolbar-actions {
    display: flex;
    gap: 10px;
}

/* ---------------- Forms ---------------- */
label {
    display: block;
    font-size: 0.85rem;
    color: var(--color-text-muted);
    margin: 12px 0 4px;
    font-weight: 600;
}
label:first-child { margin-top: 0; }

.hint-inline { font-weight: 400; color: #9aa1af; }

input[type="text"],
input[type="password"],
input[type="date"],
input[type="file"],
select {
    width: 100%;
    padding: 9px 11px;
    border: 1px solid var(--color-border);
    border-radius: 8px;
    font-size: 0.92rem;
    font-family: inherit;
    background: #fff;
    color: var(--color-text);
}

input:focus, select:focus {
    outline: none;
    border-color: var(--color-gold);
    box-shadow: 0 0 0 3px rgba(201, 162, 39, 0.18);
}

.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 4px 16px;
    align-items: end;
}

.form-grid-full { grid-column: 1 / -1; }

.hint {
    font-size: 0.85rem;
    color: var(--color-text-muted);
    background: #f8f9fc;
    border-radius: 8px;
    padding: 10px 12px;
    margin: 8px 0 14px;
}

/* ---------------- Buttons ---------------- */
.btn {
    display: inline-block;
    background: #fff;
    border: 1px solid var(--color-border);
    color: var(--color-text);
    padding: 9px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    font-weight: 600;
    cursor: pointer;
    font-family: inherit;
    transition: all 0.15s ease;
}
.btn:hover { background: #f4f6fb; text-decoration: none; }

.btn-primary {
    background: linear-gradient(160deg, #1a2c52, var(--color-primary));
    border-color: var(--color-primary);
    color: #fff;
}
.btn-primary:hover { background: var(--color-primary-dark); }

.btn-gold {
    background: linear-gradient(160deg, #e0b93a, var(--color-gold));
    border-color: var(--color-gold-dark);
    color: #14203d;
}
.btn-gold:hover { background: var(--color-gold-dark); color: #fff; }

.btn-block { width: 100%; text-align: center; margin-top: 10px; }

/* ---------------- Device grid (student borrow page) ---------------- */
.device-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(160px, 1fr));
    gap: 14px;
}

.device-card {
    border: 1px solid var(--color-border);
    border-radius: var(--radius);
    padding: 16px;
    text-align: center;
    background: #fafbfe;
}

.device-card-icon { font-size: 1.8rem; }
.device-card-code { font-weight: 700; margin-top: 6px; }
.device-card-brand { color: var(--color-text-muted); font-size: 0.85rem; margin-bottom: 8px; }

/* ---------------- Borrow status box (student dashboard) ---------------- */
.borrow-status-box {
    border-radius: var(--radius);
    padding: 16px 18px;
    border: 1px solid var(--color-border);
    background: #f8f9fc;
}
.borrow-status-box.status-active { border-left: 4px solid var(--color-blue); }
.borrow-status-box.status-overdue { border-left: 4px solid var(--color-red); background: #fff5f5; }
.borrow-status-box p { margin: 4px 0; }
.borrow-status-box .btn { margin-top: 10px; }

/* ---------------- Alerts ---------------- */
.alert {
    padding: 11px 16px;
    border-radius: 8px;
    font-size: 0.9rem;
    margin-bottom: 16px;
}
.alert-success { background: var(--color-green-bg); color: #14532d; }
.alert-error   { background: var(--color-red-bg); color: #7f1d1d; }
.alert-info    { background: var(--color-blue-bg); color: #1e3a8a; }

/* ---------------- Modal ---------------- */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(15, 20, 35, 0.5);
    align-items: center;
    justify-content: center;
    z-index: 100;
    padding: 16px;
}
.modal-overlay.open { display: flex; }

.modal {
    background: #fff;
    border-radius: var(--radius);
    padding: 24px;
    width: 100%;
    max-width: 420px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: 0 10px 40px rgba(0,0,0,0.2);
    border-top: 3px solid var(--color-gold);
}
.modal h2 { margin: 0 0 6px; font-size: 1.1rem; }

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    margin-top: 20px;
}

/* ---------------- Auth pages (login / install) ---------------- */
.auth-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background:
        radial-gradient(1200px 600px at 10% -10%, rgba(224,185,58,0.15), transparent 60%),
        linear-gradient(160deg, #0b1f3f 0%, #1a3a70 55%, #122a54 100%);
    padding: 24px;
}

.auth-box {
    background: #fff;
    border-radius: 14px;
    padding: 36px 32px;
    width: 100%;
    max-width: 380px;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3), 0 2px 0 var(--color-gold) inset;
    text-align: center;
}

.auth-logo {
    width: 76px;
    height: 76px;
    margin: 0 auto 12px;
    border-radius: 50%;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(160deg, #e0b93a, var(--color-gold));
    box-shadow: 0 8px 20px rgba(201,162,39,0.35), 0 0 0 5px var(--color-gold-bg);
    overflow: hidden;
    font-size: 2rem;
}

.auth-logo img { width: 100%; height: 100%; object-fit: cover; border-radius: 50%; }

.auth-box h1 {
    font-size: 1.25rem;
    margin: 0 0 6px;
    color: #14203d;
}

.auth-subtitle {
    color: var(--color-text-muted);
    font-size: 0.88rem;
    margin-bottom: 18px;
}

.auth-box form { text-align: left; }
.auth-box .alert { text-align: left; }

/* ---------------- Terms of use (index.php) ---------------- */
.terms-box {
    background: #fff;
    border-radius: 14px;
    padding: 32px 34px;
    width: 100%;
    max-width: 620px;
    max-height: 92vh;
    overflow-y: auto;
    box-shadow: 0 20px 60px rgba(0,0,0,0.3), 0 2px 0 var(--color-gold) inset;
    text-align: center;
}

.terms-box h1 {
    font-size: 1.3rem;
    margin: 0 0 6px;
    color: #14203d;
}

.terms-content {
    text-align: left;
    background: #f8f9fc;
    border: 1px solid var(--color-border);
    border-radius: 10px;
    padding: 18px 20px;
    margin: 18px 0;
    max-height: 320px;
    overflow-y: auto;
}

.terms-content h2 {
    font-size: 1rem;
    margin: 0 0 12px;
    color: #14203d;
    padding-bottom: 10px;
    border-bottom: 2px solid var(--color-gold);
}

.terms-content ol {
    margin: 0;
    padding-left: 20px;
    font-size: 0.9rem;
    color: var(--color-text);
}

.terms-content li { margin-bottom: 10px; line-height: 1.6; }

.terms-accept { text-align: left; }

.checkbox-label {
    display: flex;
    align-items: flex-start;
    gap: 8px;
    font-size: 0.9rem;
    font-weight: 400;
    color: var(--color-text);
    cursor: pointer;
    margin-bottom: 14px;
    padding: 12px 14px;
    background: var(--color-gold-bg);
    border: 1px solid #ecdd9c;
    border-radius: 8px;
}

.checkbox-label input[type="checkbox"] {
    width: auto;
    margin-top: 3px;
    cursor: pointer;
    accent-color: var(--color-primary);
}

.terms-accept button:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

/* ---------------- Mobile topbar (hidden on desktop) ---------------- */
.mobile-topbar {
    display: none;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
    background: linear-gradient(180deg, #0f1a33, #14203d);
    color: #fff;
    padding: 12px 16px;
    border-bottom: 3px solid var(--color-gold);
    position: sticky;
    top: 0;
    z-index: 60;
}

.mobile-topbar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    font-weight: 700;
    font-size: 1rem;
}

.mobile-topbar-brand .sidebar-brand-logo {
    width: 30px;
    height: 30px;
}

.sidebar-toggle {
    background: rgba(201, 162, 39, 0.14);
    border: 1px solid rgba(201, 162, 39, 0.35);
    color: #f5d976;
    width: 40px;
    height: 40px;
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    cursor: pointer;
    flex-shrink: 0;
    padding: 0;
}

.sidebar-toggle:hover { background: rgba(201, 162, 39, 0.24); }

.sidebar-toggle .bar {
    display: block;
    width: 20px;
    height: 2px;
    background: #f5d976;
    position: relative;
}
.sidebar-toggle .bar::before,
.sidebar-toggle .bar::after {
    content: "";
    position: absolute;
    left: 0;
    width: 20px;
    height: 2px;
    background: #f5d976;
}
.sidebar-toggle .bar::before { top: -6px; }
.sidebar-toggle .bar::after { top: 6px; }

.sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(11, 15, 26, 0.55);
    z-index: 70;
}
.sidebar-overlay.open { display: block; }

/* ---------------- Responsive ---------------- */
@media (max-width: 800px) {
    .layout { flex-direction: column; }

    .mobile-topbar { display: flex; }

    .sidebar {
        position: fixed;
        top: 0;
        left: 0;
        width: 260px;
        max-width: 82vw;
        height: 100vh;
        height: 100dvh;
        transform: translateX(-100%);
        transition: transform 0.22s ease;
        z-index: 80;
        flex-direction: column;
        overflow: hidden;
        border-right: 3px solid var(--color-gold);
        border-bottom: none;
        box-shadow: 8px 0 30px rgba(0,0,0,0.25);
    }

    .sidebar.open { transform: translateX(0); }

    .sidebar-brand { display: flex; flex-shrink: 0; }
    .sidebar-nav { flex-direction: column; overflow-y: auto; min-height: 0; }
    .sidebar-footer { display: block; flex-shrink: 0; }

    .sidebar-nav a {
        padding: 13px 14px;
        font-size: 1rem;
    }

    .content { padding: 16px; }

    .page-title { font-size: 1.25rem; }

    .stat-grid {
        grid-template-columns: repeat(2, 1fr);
        gap: 10px;
    }

    .stat-value { font-size: 1.4rem; }
    .stat-card { padding: 12px 14px; }

    .card { padding: 16px; }

    .toolbar { flex-direction: column; align-items: stretch; }
    .toolbar-actions { justify-content: stretch; }
    .toolbar-actions .btn { flex: 1; }

    .form-grid { grid-template-columns: 1fr; }

    thead th, tbody td { padding: 8px; font-size: 0.85rem; }
}

@media (max-width: 420px) {
    .stat-grid { grid-template-columns: 1fr 1fr; }
    .auth-box, .terms-box { padding: 24px 18px; }
}