:root {
    --bg: #0c3e56;
    --header: #043241;
    --card: #1e5468;
    --accent: #2a6d82;
    --accent-2: #2a6d82;
    --hover: #043241;
    --text: #ffffff;
    --muted: #b7d3de;
    --danger: #c0392b;
    --ok: #1e8449;
    --warn: #d68910;
    --radius: 12px;
    --touch: 48px;
}
* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { min-height: 100%; }
body {
    background: var(--bg);
    color: var(--text);
    font-family: 'Segoe UI', Tahoma, Geneva, Verdana, sans-serif;
    -webkit-tap-highlight-color: transparent;
}
img { max-width: 100%; }
a { color: inherit; }
button, input, select, textarea { font-family: inherit; font-size: 16px; }

.header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 10px 14px;
    background: var(--header);
    gap: 12px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.header .logo { display: flex; align-items: center; gap: 10px; text-decoration: none; min-width: 0; }
.header .logo img {
    height: 58px;
    width: auto;
    max-width: 96px;
    object-fit: contain;
    display: block;
}
.header h1 { font-size: 18px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.header .welcome { font-size: 16px; margin-left: auto; }
.header .user-info { display: flex; align-items: center; position: relative; cursor: pointer; }
.header .user-info img { width: 40px; height: 40px; border-radius: 50%; object-fit: cover; background: var(--accent); }
.header .dropdown {
    display: none;
    position: absolute;
    top: 48px;
    right: 0;
    background: var(--card);
    border-radius: 8px;
    min-width: 180px;
    overflow: hidden;
    box-shadow: 0 8px 20px rgba(0,0,0,.25);
}
.header .user-info.open .dropdown,
.header .user-info:hover .dropdown { display: block; }
.header .dropdown a { display: block; padding: 12px; text-decoration: none; text-align: center; }
.header .dropdown a:hover { background: var(--accent); }

.page { padding: 16px; max-width: 1400px; margin: 0 auto; }
.page-wide { max-width: 1600px; }

.grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 15px;
}
.box {
    padding: 20px;
    border-radius: var(--radius);
    text-align: center;
    background: var(--card);
    box-shadow: 0 4px 6px rgba(0,0,0,.12);
    color: #fff;
    text-decoration: none;
    min-height: 110px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    position: relative;
    transition: transform .25s, box-shadow .25s;
}
.box:hover { transform: translateY(-4px); box-shadow: 0 6px 12px rgba(0,0,0,.22); }
.box h3 { font-size: 17px; font-weight: 600; }
.box-alert {
    background: #c0392b !important;
    box-shadow: 0 0 0 3px rgba(192, 57, 43, .45);
    animation: pulse-alert 1.6s ease-in-out infinite;
}
.box-alert .box-status { font-weight: 800; font-size: 15px; margin-top: 8px; letter-spacing: .3px; }
.box-ok .box-status { color: #9fe6b8; margin-top: 8px; font-weight: 700; }
.box-status { font-size: 13px; color: var(--muted); margin-top: 6px; }
@keyframes pulse-alert {
    0%, 100% { transform: none; }
    50% { transform: translateY(-2px); }
}
.box .ico { position: absolute; top: 14px; right: 14px; width: 36px; height: 36px; opacity: .9; }
.box.span-2 { grid-column: span 2; background: var(--accent); font-weight: 700; font-size: 18px; }
.kpi { font-size: 28px; font-weight: 700; }
.kpi-label { font-size: 13px; color: var(--muted); }

.card {
    background: var(--card);
    border-radius: var(--radius);
    padding: 16px;
    margin-bottom: 14px;
}
.toolbar { display: flex; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; align-items: center; }
.toolbar .grow { flex: 1; min-width: 160px; }

.btn, button.btn, input[type=submit], a.btn {
    min-height: var(--touch);
    padding: 10px 16px;
    border: none;
    border-radius: 8px;
    background: var(--accent);
    color: #fff;
    cursor: pointer;
    font-weight: 600;
    text-decoration: none;
    display: inline-flex;
    align-items: center;
    justify-content: center;
}
.btn:hover, button.btn:hover { background: var(--hover); }
.btn-ok { background: var(--ok); }
.btn-danger { background: var(--danger); }
.btn-ghost { background: transparent; border: 1px solid #7aa8b8; }
.btn-lg { min-height: 56px; font-size: 18px; }

input, select, textarea {
    width: 100%;
    padding: 12px;
    border: 1px solid #3d7a90;
    border-radius: 8px;
    min-height: var(--touch);
    background: #0c3e56;
    color: #fff;
    color-scheme: dark;
}
input::placeholder, textarea::placeholder { color: #b7d3de; opacity: 1; }
option { background: #0c3e56; color: #fff; }
input[type="checkbox"], input[type="radio"] {
    width: 20px;
    min-height: 20px;
    accent-color: #5fd08a;
}
input[type="color"] { padding: 4px; min-height: 44px; }
table.data input, table.data select, table.data textarea {
    background: #fff;
    color: #111;
    border: 1px solid #ccc;
    color-scheme: light;
}
textarea { min-height: 90px; resize: vertical; }
label { display: block; margin: 10px 0 6px; font-weight: 600; font-size: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 10px 14px; }
.check-row { display: flex; flex-wrap: wrap; gap: 8px 14px; margin-top: 8px; }
.check-row label { font-weight: 500; display: flex; align-items: center; gap: 6px; min-height: 40px; }
.check-row input { width: auto; min-height: 0; }

.table-wrap { overflow: auto; -webkit-overflow-scrolling: touch; border-radius: 8px; }
table.data { width: 100%; border-collapse: collapse; background: #fff; color: #111; }
table.data th { background: var(--accent); color: #fff; padding: 10px; text-align: left; position: sticky; top: 0; }
table.data td { padding: 10px; border-bottom: 1px solid #e5e5e5; }
table.data tr:hover td { background: #f3f7f9; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }

.badge { display: inline-block; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.badge-ok { background: #1e8449; }
.badge-warn { background: #d68910; }
.badge-danger { background: #c0392b; }
.badge-info { background: var(--accent); }
.badge-muted { background: #5d6d7e; }

.layout { display: flex; min-height: calc(100vh - 70px); }
.sidebar {
    width: 240px;
    background: #2a2a2a;
    padding: 14px;
    overflow: auto;
    flex-shrink: 0;
}
.side-item {
    background: #444;
    padding: 12px;
    border-radius: 6px;
    margin-bottom: 6px;
    cursor: pointer;
    text-align: center;
}
.side-item:hover, .side-item.active { background: var(--accent); }
.main { flex: 1; padding: 16px; min-width: 0; overflow: auto; }

.modal {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,.6);
    z-index: 100;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.modal.open { display: flex; }
.modal-content {
    background: var(--card);
    color: #fff;
    padding: 18px;
    border-radius: 12px;
    width: min(640px, 100%);
    max-height: 92vh;
    overflow: auto;
    box-shadow: 0 12px 40px rgba(0,0,0,.45);
}
.modal-content h2 { margin-bottom: 12px; color: #fff; }
.modal-content.dark { background: var(--card); color: #fff; }
.modal-content.dark h2 { color: #fff; }
.modal-content label { color: #d7eef5; }
.modal-content p, .modal-content .kpi-label { color: var(--muted); }

.notifications { position: fixed; top: 16px; right: 16px; z-index: 200; display: flex; flex-direction: column; gap: 8px; }
.notification { padding: 12px 14px; border-radius: 8px; font-weight: 700; color: #fff; }
.notification.success { background: #1e8449; }
.notification.error { background: #c0392b; }

/* Login */
.login-page {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
}
.login-top { text-align: center; padding: 20px 16px 4px; }
.login-top img {
    width: min(180px, 52vw);
    height: auto;
    max-height: 180px;
    object-fit: contain;
    filter: drop-shadow(0 8px 20px rgba(0, 0, 0, .35));
}
.user-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(128px, 140px));
    justify-content: center;
    align-content: start;
    gap: 12px;
    padding: 12px 16px 80px;
    max-width: 720px;
    margin: 0 auto;
    width: 100%;
}
.user-card {
    background: var(--card);
    color: #fff;
    border-radius: 12px;
    padding: 12px 8px 10px;
    text-align: center;
    cursor: pointer;
    border: 2px solid transparent;
    min-height: 0;
    height: auto;
    box-shadow: 0 4px 8px rgba(0,0,0,.15);
}
.user-card:hover, .user-card:focus { border-color: #7ec8e3; transform: translateY(-2px); }
.user-card img { width: 56px; height: 56px; border-radius: 50%; object-fit: cover; background: var(--accent); }
.user-card .name { margin-top: 8px; font-weight: 700; font-size: 14px; color: #fff; line-height: 1.2; }
.user-card .grade { font-size: 12px; color: #c5e4ef; margin-top: 2px; }
.admin-login {
    position: fixed;
    left: 16px;
    bottom: 16px;
    z-index: 30;
}

.keypad { width: min(340px, 100%); margin: 0 auto; }
.pin-dots { display: flex; justify-content: center; gap: 10px; min-height: 28px; margin: 8px 0 14px; letter-spacing: 6px; font-size: 28px; }
.keys { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.key {
    min-height: 64px;
    font-size: 24px;
    font-weight: 700;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 10px;
    cursor: pointer;
}
.key:active { background: var(--hover); }
.key.ok { background: var(--ok); }
.key.del { background: #7f8c8d; }

.camera-box video, .camera-box img, .camera-box canvas { width: 100%; border-radius: 8px; background: #000; max-height: 360px; object-fit: cover; }

.alert-list { display: flex; flex-direction: column; gap: 8px; }
.alert-item { background: #0c3e56; padding: 10px 12px; border-radius: 8px; display: flex; justify-content: space-between; gap: 8px; }

.qty-pad { display: flex; align-items: center; gap: 8px; }
.qty-pad button { min-width: 48px; }

.preview-etiq {
    background: #fff;
    color: #000;
    padding: 8px;
    margin: 12px auto;
    font-family: Arial, Helvetica, sans-serif;
}

.equip-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(240px, 1fr));
    gap: 12px;
}
.equip-card {
    background: #0c3e56;
    border-radius: 12px;
    padding: 14px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.equip-card.missing { outline: 2px solid #e74c3c; }
.equip-card.ok { outline: 2px solid #1e8449; }
.equip-card .temp-now { font-size: 28px; font-weight: 800; }
.creneau-bar { display: flex; gap: 8px; flex-wrap: wrap; margin-bottom: 12px; }
.creneau-chip {
    flex: 1;
    min-width: 90px;
    text-align: center;
    padding: 10px;
    border-radius: 8px;
    background: #0c3e56;
    font-weight: 700;
}
.creneau-chip.active { background: var(--accent); }
.creneau-chip.done { background: #1e8449; }
.creneau-chip.miss { background: #c0392b; }

@media print {
    .header, .toolbar, .sidebar, .no-print, .notifications { display: none !important; }
    body { background: #fff; color: #000; }
    .card, .equip-card { background: #fff; color: #000; }
}

@media (max-width: 800px) {
    .header h1 { font-size: 15px; }
    .header .welcome { display: none; }
    .layout { flex-direction: column; }
    .sidebar { width: 100%; display: flex; gap: 8px; overflow: auto; }
    .side-item { white-space: nowrap; margin-bottom: 0; }
    .box.span-2 { grid-column: span 1; }
}
@media (max-width: 480px) {
    .user-grid { grid-template-columns: repeat(2, 1fr); }
    .key { min-height: 56px; }
}
