:root {
  --c-bg: #f4f7f9;
  --c-panel: #ffffff;
  --c-text: #1d2a33;
  --c-muted: #64748b;
  --c-line: #dfe6ec;
  --c-primary: #0e7490;
  --c-primary-dark: #0b5a70;
  --c-primary-soft: #e0f2f7;
  --c-green: #15803d; --c-green-soft: #dcfce7;
  --c-orange: #b45309; --c-orange-soft: #fef3c7;
  --c-red: #b91c1c; --c-red-soft: #fee2e2;
  --c-grey-soft: #eef2f5;
  --radius: 8px;
  --sidebar: 220px;
}
* { box-sizing: border-box; }
html { font-size: 15px; }
body { margin: 0; font-family: system-ui, -apple-system, "Segoe UI", Roboto, Arial, sans-serif; background: var(--c-bg); color: var(--c-text); line-height: 1.45; }
a { color: var(--c-primary); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.6rem; margin: 0; }
h2 { font-size: 1.2rem; margin: 1.6rem 0 .7rem; }
h3 { font-size: 1.05rem; margin: 1.2rem 0 .5rem; }

/* Layout */
.topbar { position: fixed; top: 0; left: 0; right: 0; height: 54px; background: var(--c-primary); color: #fff; display: flex; align-items: center; padding: 0 1rem; gap: 1rem; z-index: 20; }
.topbar a { color: #fff; }
.brand { font-weight: 700; font-size: 1.1rem; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.logo { display: inline-block; background: rgba(255,255,255,.2); border-radius: 6px; padding: 0 .4rem; }
.userbox { margin-left: auto; display: flex; gap: .8rem; align-items: center; font-size: .9rem; }
.userbox .role { background: rgba(255,255,255,.18); padding: .1rem .5rem; border-radius: 99px; font-size: .8rem; }
.nav-toggle { display: none; background: none; border: 0; color: #fff; font-size: 1.4rem; cursor: pointer; }
.sidebar { position: fixed; top: 54px; bottom: 0; left: 0; width: var(--sidebar); background: var(--c-panel); border-right: 1px solid var(--c-line); overflow-y: auto; padding: .8rem 0; z-index: 15; }
.sidebar ul { list-style: none; margin: 0; padding: 0; }
.sidebar a { display: block; padding: .55rem 1.2rem; color: var(--c-text); border-left: 3px solid transparent; }
.sidebar a:hover { background: var(--c-grey-soft); text-decoration: none; }
.sidebar a.active { background: var(--c-primary-soft); border-left-color: var(--c-primary); color: var(--c-primary-dark); font-weight: 600; }
.nav-section { padding: 1rem 1.2rem .3rem; font-size: .75rem; text-transform: uppercase; letter-spacing: .06em; color: var(--c-muted); }
.content { padding: 1.4rem 1.6rem 3rem; }
body.has-nav .content { margin-left: var(--sidebar); margin-top: 54px; }
body.no-nav .content { max-width: 420px; margin: 8vh auto; }
.page-head { display: flex; flex-wrap: wrap; align-items: center; gap: .8rem 1rem; margin-bottom: 1.2rem; }
.page-head .actions { margin-left: auto; display: flex; gap: .5rem; flex-wrap: wrap; }

@media (max-width: 860px) {
  .nav-toggle { display: block; }
  .sidebar { transform: translateX(-100%); transition: transform .2s; box-shadow: 2px 0 10px rgba(0,0,0,.1); }
  body.nav-open .sidebar { transform: none; }
  body.has-nav .content { margin-left: 0; padding: 1rem; }
  .userbox .role, .userbox > a:first-child { display: none; }
}

/* Panels */
.card { background: var(--c-panel); border: 1px solid var(--c-line); border-radius: var(--radius); padding: 1.1rem 1.2rem; margin-bottom: 1.2rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.grid { display: grid; gap: 1.2rem; }
.grid-2 { grid-template-columns: repeat(auto-fit, minmax(320px, 1fr)); }
.grid-3 { grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 1rem; margin-bottom: 1.2rem; }
.stat { background: var(--c-panel); border: 1px solid var(--c-line); border-radius: var(--radius); padding: .9rem 1rem; }
.stat .num { font-size: 1.7rem; font-weight: 700; }
.stat .lbl { color: var(--c-muted); font-size: .85rem; }
.stat.warn .num { color: var(--c-orange); }
.stat.bad .num { color: var(--c-red); }

/* Tables */
.table-wrap { overflow-x: auto; background: var(--c-panel); border: 1px solid var(--c-line); border-radius: var(--radius); margin-bottom: 1.2rem; }
.card .table-wrap { border: 0; margin: 0 -1.2rem; border-radius: 0; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: .5rem .7rem; border-bottom: 1px solid var(--c-line); vertical-align: top; }
th { background: #f8fafb; font-size: .82rem; color: var(--c-muted); font-weight: 600; white-space: nowrap; }
tr:last-child td { border-bottom: 0; }
tbody tr:hover { background: #fafcfd; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.nowrap { white-space: nowrap; }
tr.muted td { color: var(--c-muted); }
tr.cancelled td { color: var(--c-muted); text-decoration: line-through; }
tfoot td { font-weight: 700; background: #f8fafb; }
.empty { color: var(--c-muted); padding: 1rem; text-align: center; }

/* Forms */
form.inline { display: inline; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: .3rem 1rem; }
.form-grid .wide { grid-column: 1 / -1; }
.field { margin-bottom: .8rem; }
.field label { display: block; font-size: .85rem; font-weight: 600; margin-bottom: .25rem; color: #334155; }
.field small { display: block; color: var(--c-muted); font-size: .8rem; margin-top: .2rem; }
input[type=text], input[type=email], input[type=tel], input[type=date], input[type=time], input[type=number], input[type=password], input[type=month], input[type=search], select, textarea {
  width: 100%; padding: .5rem .6rem; border: 1px solid #c8d3dc; border-radius: 6px; font: inherit; background: #fff; color: inherit;
}
textarea { min-height: 80px; resize: vertical; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--c-primary-soft); border-color: var(--c-primary); }
.field-check label { font-weight: normal; display: flex; align-items: center; gap: .4rem; padding-top: 1.6rem; }
.checks { display: flex; flex-wrap: wrap; gap: .4rem 1rem; }
.checks label { font-weight: normal; display: inline-flex; align-items: center; gap: .3rem; }
fieldset { border: 1px solid var(--c-line); border-radius: var(--radius); padding: .8rem 1rem .2rem; margin: 0 0 1rem; }
legend { font-weight: 700; padding: 0 .4rem; }
.form-actions { display: flex; gap: .6rem; align-items: center; margin-top: .6rem; flex-wrap: wrap; }
.filters { display: flex; flex-wrap: wrap; gap: .6rem; align-items: flex-end; margin-bottom: 1rem; }
.filters .field { margin: 0; min-width: 140px; }
.filters .field-check label { padding-top: 0; }

/* Buttons */
.btn { display: inline-block; border: 1px solid var(--c-primary); background: var(--c-primary); color: #fff; padding: .5rem 1rem; border-radius: 6px; font: inherit; font-weight: 600; cursor: pointer; line-height: 1.2; white-space: nowrap; }
.btn:hover { background: var(--c-primary-dark); text-decoration: none; color: #fff; }
.btn-secondary { background: #fff; color: var(--c-primary); }
.btn-secondary:hover { background: var(--c-primary-soft); color: var(--c-primary-dark); }
.btn-danger { background: #fff; color: var(--c-red); border-color: #f1b5b5; }
.btn-danger:hover { background: var(--c-red-soft); color: var(--c-red); }
.btn-small { padding: .25rem .6rem; font-size: .82rem; font-weight: 500; }

/* Badges & alerts */
.badge { display: inline-block; padding: .08rem .5rem; border-radius: 99px; font-size: .78rem; background: var(--c-grey-soft); color: #475569; white-space: nowrap; }
.badge.green { background: var(--c-green-soft); color: var(--c-green); }
.badge.orange { background: var(--c-orange-soft); color: var(--c-orange); }
.badge.red { background: var(--c-red-soft); color: var(--c-red); }
.badge.blue { background: var(--c-primary-soft); color: var(--c-primary-dark); }
.alert { padding: .7rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; border: 1px solid; }
.alert-success { background: var(--c-green-soft); border-color: #a7e3bd; color: #14532d; }
.alert-error { background: var(--c-red-soft); border-color: #f5b5b5; color: #7f1d1d; }
.alert-warning { background: var(--c-orange-soft); border-color: #f5d98b; color: #78350f; }
.alert-info { background: var(--c-primary-soft); border-color: #a5d8e6; color: #0b4a5c; }
.muted { color: var(--c-muted); }
.small { font-size: .85rem; }
.pre { white-space: pre-wrap; }
dl.props { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.props dt { color: var(--c-muted); font-size: .88rem; }
dl.props dd { margin: 0; }

/* Tabs */
.tabs { display: flex; gap: .2rem; border-bottom: 1px solid var(--c-line); margin-bottom: 1rem; flex-wrap: wrap; }
.tabs a { padding: .55rem .9rem; border-bottom: 2px solid transparent; color: var(--c-muted); font-weight: 600; }
.tabs a.active { color: var(--c-primary-dark); border-bottom-color: var(--c-primary); }
.tabs a:hover { text-decoration: none; color: var(--c-text); }
.tab-panel { display: none; }
.tab-panel.active { display: block; }

/* Calendar */
.cal-head { display: flex; align-items: center; gap: .6rem; margin-bottom: 1rem; flex-wrap: wrap; }
.cal-head h2 { margin: 0 .6rem; min-width: 11rem; text-align: center; }
.calendar { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); background: var(--c-line); gap: 1px; border: 1px solid var(--c-line); border-radius: var(--radius); overflow: hidden; }
.calendar .dow { background: #f8fafb; padding: .4rem; text-align: center; font-size: .8rem; font-weight: 600; color: var(--c-muted); }
.calendar .day { background: #fff; min-height: 105px; padding: .3rem; }
.calendar .day.other { background: #f8fafb; }
.calendar .day.other .dnum { color: #b4c0ca; }
.calendar .day.today { background: #f0fafc; }
.calendar .day.today .dnum { background: var(--c-primary); color: #fff; border-radius: 99px; padding: 0 .4rem; }
.dnum { font-size: .8rem; font-weight: 700; display: inline-block; margin-bottom: .2rem; }
.ev { display: block; font-size: .76rem; background: var(--c-primary-soft); color: var(--c-primary-dark); border-left: 3px solid var(--c-primary); border-radius: 4px; padding: .15rem .3rem; margin-bottom: .2rem; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev:hover { text-decoration: none; filter: brightness(.96); }
.ev.surf { background: #fff7ed; color: #9a3412; border-left-color: #ea580c; }
.ev.done { border-left-color: var(--c-green); }
.ev.cancelled { text-decoration: line-through; opacity: .6; }
@media (max-width: 700px) {
  .calendar { display: block; background: none; border: 0; }
  .calendar .dow, .calendar .day.other, .calendar .day.empty { display: none; }
  .calendar .day { min-height: 0; border: 1px solid var(--c-line); border-radius: 6px; margin-bottom: .4rem; }
}

/* Attendance */
.att-table select { min-width: 110px; }
.att-table td { vertical-align: middle; }
.att-table input[type=text] { min-width: 160px; }
@media (max-width: 700px) {
  .att-table thead { display: none; }
  .att-table, .att-table tbody, .att-table tr { display: block; }
  .att-table tr { padding: .6rem .7rem; border-bottom: 1px solid var(--c-line); display: grid; grid-template-columns: 1fr 1fr; gap: .4rem; }
  .att-table td { display: block; border: 0; padding: 0; }
  .att-table td:nth-child(1), .att-table td:nth-child(2), .att-table td:nth-child(5) { grid-column: 1 / -1; }
  .att-table select, .att-table input[type=text] { min-width: 0; }
}
.matrix th.rot { writing-mode: vertical-rl; transform: rotate(180deg); white-space: nowrap; padding: .4rem .2rem; font-size: .75rem; }
.matrix td.c { text-align: center; padding: .3rem; }
.att-p { color: var(--c-green); font-weight: 700; }
.att-o { color: var(--c-orange); }
.att-n { color: var(--c-red); }

.login-box { background: var(--c-panel); border: 1px solid var(--c-line); border-radius: var(--radius); padding: 1.6rem; }
.login-box h1 { margin-bottom: 1rem; }
.health { background: var(--c-orange-soft); border-radius: 4px; padding: .05rem .35rem; font-size: .8rem; color: var(--c-orange); }
@media print {
  .sidebar, .topbar, .actions, .filters, .btn, form.inline { display: none !important; }
  body.has-nav .content { margin: 0; }
}
