/* =====================================================================
   FFC Gate Entry System PRO - Design tokens & base
   ===================================================================== */

:root {
    --navy-950: #0B1730;
    --navy-900: #0F1E3D;
    --navy-800: #16295C;
    --navy-700: #1E3A72;
    --gold-500: #E3A73B;
    --gold-600: #C98F27;
    --gold-100: #FCF1DC;
    --green-500: #189A5C;
    --green-100: #E4F6EC;
    --red-500: #E14F4F;
    --red-100: #FBE7E7;
    --blue-500: #2F6FED;
    --blue-100: #E8EFFD;
    --gray-500: #7C879C;
    --gray-100: #EEF1F6;

    --bg: #F3F5FA;
    --surface: #FFFFFF;
    --surface-alt: #FAFBFD;
    --border: #E3E7F0;
    --ink-900: #121A2E;
    --ink-600: #4B5468;
    --ink-400: #8891A5;

    --radius-sm: 8px;
    --radius-md: 14px;
    --radius-lg: 20px;
    --shadow-sm: 0 1px 2px rgba(15, 30, 61, 0.06);
    --shadow-md: 0 6px 20px rgba(15, 30, 61, 0.08);
    --shadow-lg: 0 16px 40px rgba(15, 30, 61, 0.14);

    --font-display: 'Sora', 'Segoe UI', sans-serif;
    --font-body: 'Inter', 'Segoe UI', sans-serif;
    --font-mono: 'IBM Plex Mono', 'Consolas', monospace;
}

* { box-sizing: border-box; }
html, body {
    margin: 0; padding: 0;
    background: var(--bg);
    color: var(--ink-900);
    font-family: var(--font-body);
    font-size: 14.5px;
    -webkit-font-smoothing: antialiased;
}
h1, h2, h3, h4 { font-family: var(--font-display); margin: 0 0 6px; color: var(--navy-900); }
h1 { font-size: 26px; font-weight: 700; }
h2 { font-size: 19px; font-weight: 700; }
h3 { font-size: 15px; font-weight: 600; }
p { margin: 0 0 10px; color: var(--ink-600); }
a { color: var(--blue-500); text-decoration: none; }
a:hover { text-decoration: underline; }
code, .mono { font-family: var(--font-mono); }
::selection { background: var(--gold-100); }

.app-shell { display: flex; min-height: 100vh; }

.sidebar {
    width: 230px; flex-shrink: 0;
    background: linear-gradient(180deg, var(--navy-950), var(--navy-800));
    color: #fff; display: flex; flex-direction: column;
    position: sticky; top: 0; height: 100vh;
}
.sidebar-brand { display: flex; align-items: center; gap: 10px; padding: 22px 20px 18px; border-bottom: 1px solid rgba(255,255,255,0.08); }
.sidebar-brand .mark { width: 36px; height: 36px; border-radius: 10px; background: var(--gold-500); display: flex; align-items: center; justify-content: center; font-family: var(--font-display); font-weight: 800; color: var(--navy-950); font-size: 15px; }
.sidebar-brand .name { font-family: var(--font-display); font-weight: 700; font-size: 14px; line-height: 1.25; }
.sidebar-brand .sub { font-size: 10.5px; color: rgba(255,255,255,0.55); letter-spacing: .04em; }

.sidebar-nav { flex: 1; padding: 14px 12px; overflow-y: auto; }
.sidebar-nav a { display: flex; align-items: center; gap: 10px; padding: 10px 12px; margin-bottom: 2px; border-radius: var(--radius-sm); color: rgba(255,255,255,0.72); font-size: 13.5px; font-weight: 500; text-decoration: none; transition: background .15s, color .15s; }
.sidebar-nav a:hover { background: rgba(255,255,255,0.06); color: #fff; }
.sidebar-nav a.active { background: var(--gold-500); color: var(--navy-950); font-weight: 700; }
.sidebar-nav .icon { width: 18px; text-align: center; font-size: 14px; }
.sidebar-nav .divider { height: 1px; background: rgba(255,255,255,0.08); margin: 10px 4px; }
.sidebar-nav .label-sm { font-size: 10.5px; text-transform: uppercase; letter-spacing: .08em; color: rgba(255,255,255,0.35); padding: 12px 12px 4px; }

.sidebar-foot { padding: 14px 16px; border-top: 1px solid rgba(255,255,255,0.08); font-size: 11.5px; color: rgba(255,255,255,0.45); }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar { height: 64px; flex-shrink: 0; background: var(--surface); border-bottom: 1px solid var(--border); display: flex; align-items: center; justify-content: space-between; padding: 0 24px; position: sticky; top: 0; z-index: 20; }
.topbar-left { display: flex; align-items: center; gap: 10px; min-width: 0; }
.topbar .page-title { font-family: var(--font-display); font-weight: 700; font-size: 17px; color: var(--navy-900); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.topbar .page-sub { font-size: 12px; color: var(--ink-400); margin-top: 1px; }
.topbar-right { display: flex; align-items: center; gap: 14px; }

.menu-toggle { display: none; align-items: center; justify-content: center; width: 38px; height: 38px; flex-shrink: 0; border-radius: var(--radius-sm); border: 1px solid var(--border); background: var(--surface); font-size: 18px; color: var(--navy-900); cursor: pointer; }
.sidebar-backdrop { display: none; position: fixed; inset: 0; background: rgba(6,12,27,0.55); z-index: 45; }
.sidebar-backdrop.open { display: block; }

.live-pill { display: inline-flex; align-items: center; gap: 7px; background: var(--green-100); color: var(--green-500); padding: 6px 12px 6px 10px; border-radius: 999px; font-size: 12px; font-weight: 700; letter-spacing: .02em; }
.live-dot { width: 8px; height: 8px; border-radius: 50%; background: var(--green-500); position: relative; }
.live-dot::after { content: ''; position: absolute; inset: -4px; border-radius: 50%; border: 2px solid var(--green-500); opacity: .5; animation: pulse-ring 1.8s cubic-bezier(.4,0,.6,1) infinite; }
@keyframes pulse-ring { 0% { transform: scale(.6); opacity: .7; } 100% { transform: scale(1.9); opacity: 0; } }
@media (prefers-reduced-motion: reduce) { .live-dot::after { animation: none; } }

.btn { display: inline-flex; align-items: center; gap: 7px; padding: 9px 16px; border-radius: var(--radius-sm); font-family: var(--font-body); font-weight: 600; font-size: 13px; border: 1px solid transparent; cursor: pointer; transition: transform .1s ease, box-shadow .15s ease, background .15s ease; text-decoration: none; }
.btn:active { transform: translateY(1px); }
.btn-gold { background: var(--gold-500); color: var(--navy-950); box-shadow: 0 2px 0 var(--gold-600); }
.btn-gold:hover { background: #ecb552; text-decoration: none; }
.btn-navy { background: var(--navy-900); color: #fff; }
.btn-navy:hover { background: var(--navy-800); text-decoration: none; color: #fff; }
.btn-green { background: var(--green-500); color: #fff; }
.btn-green:hover { background: #148050; text-decoration: none; color: #fff; }
.btn-red { background: var(--red-500); color: #fff; }
.btn-red:hover { background: #c93f3f; text-decoration: none; color: #fff; }
.btn-outline { background: var(--surface); color: var(--navy-900); border-color: var(--border); }
.btn-outline:hover { background: var(--surface-alt); text-decoration: none; }
.btn-sm { padding: 6px 11px; font-size: 12px; }
.btn[disabled] { opacity: .5; cursor: not-allowed; }

.content { padding: 24px; flex: 1; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); box-shadow: var(--shadow-sm); padding: 20px; margin-bottom: 20px; }
.card-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 14px; flex-wrap: wrap; gap: 10px; }

.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 14px; margin-bottom: 20px; }
.stat-tile { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-md); padding: 16px 18px; box-shadow: var(--shadow-sm); position: relative; overflow: hidden; }
.stat-tile::before { content: ''; position: absolute; left: 0; top: 0; bottom: 0; width: 4px; background: var(--bar, var(--navy-800)); }
.stat-tile .label { font-size: 11px; font-weight: 700; letter-spacing: .05em; text-transform: uppercase; color: var(--ink-400); }
.stat-tile .value { font-family: var(--font-display); font-size: 30px; font-weight: 700; color: var(--navy-900); margin-top: 4px; }
.stat-tile.c-navy { --bar: var(--navy-800); }
.stat-tile.c-gold { --bar: var(--gold-500); }
.stat-tile.c-green { --bar: var(--green-500); }
.stat-tile.c-blue { --bar: var(--blue-500); }
.stat-tile.c-red { --bar: var(--red-500); }
.stat-tile.c-gray { --bar: var(--gray-500); }

.badge { display: inline-flex; align-items: center; gap: 5px; padding: 3px 10px; border-radius: 999px; font-size: 11.5px; font-weight: 700; letter-spacing: .01em; white-space: nowrap; }
.badge-green { background: var(--green-100); color: var(--green-500); }
.badge-red { background: var(--red-100); color: var(--red-500); }
.badge-blue { background: var(--blue-100); color: var(--blue-500); }
.badge-amber, .badge-gold { background: var(--gold-100); color: var(--gold-600); }
.badge-navy { background: #E7EBF5; color: var(--navy-800); }
.badge-gray { background: var(--gray-100); color: var(--gray-500); }
.badge-pink { background: #FCE7F1; color: #C43B7D; }
.badge-dot { width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

.table-wrap { overflow-x: auto; border-radius: var(--radius-md); border: 1px solid var(--border); }
table.grid { width: 100%; border-collapse: collapse; background: var(--surface); font-size: 13px; }
table.grid th { background: var(--surface-alt); text-align: left; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-400); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
table.grid td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; color: var(--ink-900); }
table.grid tbody tr:hover { background: var(--surface-alt); }
table.grid tbody tr:last-child td { border-bottom: none; }
table.grid td.num, table.grid th.num { text-align: right; font-family: var(--font-mono); }
table.grid td.center, table.grid th.center { text-align: center; }

label { display: block; font-size: 12.5px; font-weight: 600; color: var(--ink-600); margin-bottom: 5px; }
.field { margin-bottom: 14px; }
input[type=text], input[type=password], input[type=number], input[type=date],
input[type=datetime-local], input[type=search], input[type=email], input[type=file], input[type=time],
select, textarea {
    width: 100%; padding: 9px 12px; border: 1px solid var(--border); border-radius: var(--radius-sm);
    background: var(--surface); color: var(--ink-900); font-family: var(--font-body); font-size: 13.5px;
}
input:focus, select:focus, textarea:focus { outline: none; border-color: var(--gold-500); box-shadow: 0 0 0 3px var(--gold-100); }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px 18px; }
.hint { font-size: 11.5px; color: var(--ink-400); margin-top: 4px; }
.toolbar { display: flex; align-items: flex-end; gap: 10px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .field { margin-bottom: 0; min-width: 150px; }

.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; background: radial-gradient(1200px 700px at 20% -10%, #1E3A72 0%, var(--navy-950) 55%, #060C1B 100%); padding: 20px; }
.login-card { width: 100%; max-width: 380px; background: var(--surface); border-radius: var(--radius-lg); box-shadow: var(--shadow-lg); padding: 34px 32px; }
.login-card .mark { width: 50px; height: 50px; border-radius: 14px; background: var(--gold-500); display: flex; align-items: center; justify-content: center; margin: 0 auto 16px; font-family: var(--font-display); font-weight: 800; color: var(--navy-950); font-size: 20px; }
.login-card h1 { text-align: center; font-size: 19px; }
.login-card .sub { text-align: center; font-size: 12.5px; color: var(--ink-400); margin-bottom: 22px; }
.login-error { background: var(--red-100); color: var(--red-500); padding: 10px 12px; border-radius: var(--radius-sm); font-size: 12.5px; margin-bottom: 16px; }

.att-sheet { font-size: 12px; }
.att-sheet th, .att-sheet td { padding: 6px 8px; }
.att-sheet .day-col { width: 30px; text-align: center; }
.att-sheet .rest-col { background: var(--red-100); }
.att-sheet .mark-P { color: var(--green-500); font-weight: 700; }
.att-sheet .mark-A { color: var(--red-500); font-weight: 700; }
.att-sheet .mark-R { color: var(--gray-500); font-weight: 700; }
.att-sheet .ot-num { display: block; font-size: 9.5px; color: var(--gold-600); font-family: var(--font-mono); }
.att-sheet .name-col { min-width: 160px; font-weight: 600; }

.photo-box { width: 120px; height: 120px; border-radius: var(--radius-md); border: 2px dashed var(--border); background: var(--surface-alt); display: flex; align-items: center; justify-content: center; overflow: hidden; }
.photo-box img { width: 100%; height: 100%; object-fit: cover; }
.photo-placeholder { font-size: 46px; color: var(--gray-500); opacity: .5; }

input:disabled, select:disabled, textarea:disabled { background: var(--surface-alt); color: var(--ink-400); cursor: not-allowed; }

.perm-grid { display: grid; grid-template-columns: repeat(auto-fill, minmax(230px, 1fr)); gap: 8px; margin: 10px 0 16px; }
.perm-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; border: 1px solid var(--border); border-radius: var(--radius-sm); background: var(--surface-alt); font-size: 13px; }
.perm-item input { width: auto; }

.timeline { position: relative; padding-left: 22px; }
.timeline::before { content: ''; position: absolute; left: 6px; top: 4px; bottom: 4px; width: 2px; background: var(--border); }
.timeline-item { position: relative; padding-bottom: 18px; }
.timeline-item::before { content: ''; position: absolute; left: -22px; top: 3px; width: 10px; height: 10px; border-radius: 50%; background: var(--gold-500); border: 2px solid var(--surface); }
.timeline-item.current::before { background: var(--green-500); }
.timeline-item .period { font-size: 11px; color: var(--ink-400); font-family: var(--font-mono); }
.timeline-item .body { background: var(--surface-alt); border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 10px 12px; margin-top: 4px; font-size: 13px; }

.flex { display: flex; }
.flex-between { display: flex; align-items: center; justify-content: space-between; }
.gap-8 { gap: 8px; } .gap-12 { gap: 12px; }
.muted { color: var(--ink-400); }
.text-right { text-align: right; }
.mt-0 { margin-top: 0; } .mb-0 { margin-bottom: 0; }
.empty-state { text-align: center; padding: 50px 20px; color: var(--ink-400); }
.empty-state .big-icon { font-size: 38px; margin-bottom: 10px; opacity: .5; }

.toast { position: fixed; bottom: 24px; right: 24px; z-index: 100; background: var(--navy-950); color: #fff; padding: 12px 18px; border-radius: var(--radius-sm); box-shadow: var(--shadow-lg); font-size: 13px; font-weight: 600; display: none; max-width: 360px; }
.toast.show { display: block; }
.toast.err { background: var(--red-500); }
.toast.ok { background: var(--green-500); }

@media (max-width: 900px) {
    .sidebar { position: fixed; left: -260px; top: 0; bottom: 0; z-index: 50; transition: left .2s; width: 230px; }
    .sidebar.open { left: 0; box-shadow: var(--shadow-lg); }
    .menu-toggle { display: inline-flex; }
    .content { padding: 14px; }
    .topbar { padding: 0 14px; gap: 8px; }
    .topbar-right { gap: 8px; }
    .live-pill-text { display: none; }
    .live-pill { padding: 7px; }
    .btn { padding: 10px 14px; font-size: 13.5px; }
    .btn-sm { padding: 8px 12px; }

    /* 16px+ inputs stop iOS Safari from auto-zooming when a field is focused */
    input[type=text], input[type=password], input[type=number], input[type=date],
    input[type=datetime-local], input[type=search], input[type=email], input[type=file], input[type=time],
    select, textarea { font-size: 16px; padding: 10px 12px; }

    .card { padding: 14px; }
    .stat-grid { grid-template-columns: repeat(auto-fit, minmax(130px, 1fr)); gap: 10px; }
    .form-grid { grid-template-columns: 1fr; }
    table.grid th, table.grid td { padding: 9px 10px; font-size: 12.5px; }
}

@media (max-width: 480px) {
    .topbar .page-sub { display: none; }
    .stat-grid { grid-template-columns: repeat(2, 1fr); }
    .toolbar .field { min-width: 0; flex: 1 1 100%; }
}

@media print {
    .sidebar, .topbar, .no-print { display: none !important; }
    .content { padding: 0; }
    body { background: #fff; }
    .card { box-shadow: none; border: 1px solid #ccc; }
}
