/* Theme follows tf-ui (crm): Poppins, brand navy/blue, 4px controls, 12px cards. */
@font-face { font-family: 'Poppins'; src: url('/fonts/Poppins-Regular.ttf') format('truetype'); font-weight: 400; font-display: swap; }
@font-face { font-family: 'Poppins'; src: url('/fonts/Poppins-Medium.ttf') format('truetype'); font-weight: 500; font-display: swap; }
@font-face { font-family: 'Poppins'; src: url('/fonts/Poppins-SemiBold.ttf') format('truetype'); font-weight: 600; font-display: swap; }

:root {
  color-scheme: light;
  --brand-navy: #0F3D4D;
  --light-navy: #026c89;
  --brand-blue: #18a8c8;
  --bg: #f5f5f5;
  --surface: #ffffff;
  --surface-2: #f8fbfc;
  --surface-hover: #e5faff;
  --text: #272727;
  --text-2: #4f4f4f;
  --muted: #a1a1a1;
  --border: #d4d4d4;
  --border-soft: #e6ecee;
  --primary: #026c89;
  --primary-hover: #0F3D4D;
  --primary-text: #ffffff;
  --focus: #18a8c8;
  --link: #026c89;
  --sidebar-bg: #0F3D4D;
  --sidebar-text: #d0e2e9;
  --sidebar-active: #026c89;
  --sidebar-hover: #234f60;
  --success: #01C67E; --success-bg: #d0f6e8; --success-text: #00754a;
  --warning: #FFB300; --warning-bg: #fff4dc; --warning-text: #8a5a00;
  --danger: #e41738; --danger-bg: #ffeeeb; --danger-text: #b0102a;
  --info: #18a8c8; --info-bg: #e5faff; --info-text: #026c89;
  --neutral-bg: #f5f5f5; --neutral-text: #4d4d4d;
  --holiday-bg: #fff4dc;
  --weekend-bg: #f8fbfc;
  --shadow: 0 2px 8px rgba(15, 61, 77, .08);
  --shadow-lg: 0 12px 32px rgba(15, 61, 77, .22);
  --radius: 4px;
  --radius-card: 12px;
  --font: 'Poppins', system-ui, -apple-system, 'Segoe UI', sans-serif;
}

@media (prefers-color-scheme: dark) {
  :root:not([data-theme="light"]) {
    color-scheme: dark;
    --bg: #0a1c23; --surface: #102a34; --surface-2: #0d232c; --surface-hover: #163a47;
    --text: #e6ecee; --text-2: #b8ccd3; --muted: #7d98a2; --border: #234f60; --border-soft: #1b3f4c;
    --primary: #18a8c8; --primary-hover: #3bb5d0; --primary-text: #06212a; --link: #5dc2d9;
    --sidebar-bg: #071820; --sidebar-text: #b8ccd3; --sidebar-active: #026c89; --sidebar-hover: #123343;
    --success-bg: #0d3b2c; --success-text: #5fe0ad; --warning-bg: #3b2e0b; --warning-text: #ffcf5c;
    --danger-bg: #44141d; --danger-text: #ff8fa0; --info-bg: #0f3442; --info-text: #8cd4e4;
    --neutral-bg: #1b3a45; --neutral-text: #b8ccd3; --holiday-bg: #3b2e0b; --weekend-bg: #0d232c;
    --shadow: 0 2px 8px rgba(0, 0, 0, .35); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
  }
}
:root[data-theme="dark"] {
  color-scheme: dark;
  --bg: #0a1c23; --surface: #102a34; --surface-2: #0d232c; --surface-hover: #163a47;
  --text: #e6ecee; --text-2: #b8ccd3; --muted: #7d98a2; --border: #234f60; --border-soft: #1b3f4c;
  --primary: #18a8c8; --primary-hover: #3bb5d0; --primary-text: #06212a; --link: #5dc2d9;
  --sidebar-bg: #071820; --sidebar-text: #b8ccd3; --sidebar-active: #026c89; --sidebar-hover: #123343;
  --success-bg: #0d3b2c; --success-text: #5fe0ad; --warning-bg: #3b2e0b; --warning-text: #ffcf5c;
  --danger-bg: #44141d; --danger-text: #ff8fa0; --info-bg: #0f3442; --info-text: #8cd4e4;
  --neutral-bg: #1b3a45; --neutral-text: #b8ccd3; --holiday-bg: #3b2e0b; --weekend-bg: #0d232c;
  --shadow: 0 2px 8px rgba(0, 0, 0, .35); --shadow-lg: 0 12px 32px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; }
html, body { margin: 0; height: 100%; }
body { background: var(--bg); color: var(--text); font: 400 14px/1.5 var(--font); -webkit-font-smoothing: antialiased; }
a { color: var(--link); }
h1 { font-size: 22px; font-weight: 600; margin: 0; }
h2 { font-size: 16px; font-weight: 600; margin: 0 0 12px; }
button, input, select, textarea { font: inherit; color: inherit; }
:focus-visible { outline: 2px solid var(--focus); outline-offset: 2px; }

/* Layout */
.shell { display: grid; grid-template-columns: 232px 1fr; min-height: 100vh; }
.sidebar { background: var(--sidebar-bg); color: var(--sidebar-text); display: flex; flex-direction: column; padding: 16px 12px; position: sticky; top: 0; height: 100vh; }
.brand { display: flex; align-items: center; gap: 10px; font-weight: 600; font-size: 17px; color: #fff; padding: 4px 8px 20px; }
.brand img { width: 30px; height: 30px; }
.nav { display: flex; flex-direction: column; gap: 2px; flex: 1; overflow-y: auto; }
.nav-section { font-size: 11px; text-transform: uppercase; letter-spacing: .08em; color: var(--muted); padding: 16px 12px 6px; }
.nav a { display: flex; align-items: center; gap: 10px; padding: 9px 12px; border-radius: var(--radius); color: var(--sidebar-text); text-decoration: none; font-weight: 500; }
.nav a:hover { background: var(--sidebar-hover); color: #fff; }
.nav a.active { background: var(--sidebar-active); color: #fff; }
.nav .count { margin-left: auto; background: var(--warning); color: #272727; border-radius: 10px; font-size: 11px; font-weight: 600; padding: 0 7px; }
.side-foot { border-top: 1px solid var(--sidebar-hover); padding-top: 12px; display: flex; flex-direction: column; gap: 6px; }
.side-user { font-size: 13px; color: #fff; padding: 0 8px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.side-user small { display: block; color: var(--sidebar-text); font-size: 11px; }
.side-btn { background: transparent; border: 0; color: var(--sidebar-text); text-align: left; padding: 7px 8px; border-radius: var(--radius); cursor: pointer; display: flex; gap: 8px; align-items: center; }
.side-btn:hover { background: var(--sidebar-hover); color: #fff; }
.topbar { display: none; }
.shell > div { min-width: 0; }
.main { padding: 24px 28px 48px; min-width: 0; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; flex-wrap: wrap; margin-bottom: 20px; }
.page-head .tools { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* Cards */
.card { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius-card); box-shadow: var(--shadow); padding: 16px 18px; margin-bottom: 20px; }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: 14px; margin-bottom: 20px; }
.bal { background: var(--surface); border: 1px solid var(--border-soft); border-radius: var(--radius-card); box-shadow: var(--shadow); padding: 14px 16px; border-top: 4px solid var(--c, var(--primary)); }
.bal .t { display: flex; align-items: center; gap: 8px; font-weight: 600; }
.bal .big { font-size: 28px; font-weight: 600; line-height: 1.2; margin-top: 8px; }
.bal .big small { font-size: 13px; color: var(--text-2); font-weight: 400; }
.bal dl { display: grid; grid-template-columns: 1fr auto; gap: 2px 10px; margin: 8px 0 0; font-size: 12px; color: var(--text-2); }
.bal dd { margin: 0; text-align: right; color: var(--text); font-weight: 500; }
.bal .until { font-size: 12px; color: var(--muted); margin-top: 6px; }
.hint { background: var(--warning-bg); color: var(--warning-text); border-radius: var(--radius); padding: 10px 14px; margin-bottom: 14px; }
.note { color: var(--text-2); font-size: 13px; }

/* Buttons */
.btn { display: inline-flex; align-items: center; justify-content: center; gap: 6px; border: 1px solid var(--primary); background: var(--primary); color: var(--primary-text); padding: 7px 16px; border-radius: var(--radius); font-weight: 500; cursor: pointer; white-space: nowrap; min-height: 36px; text-decoration: none; }
.btn:hover { background: var(--primary-hover); border-color: var(--primary-hover); }
.btn:disabled { opacity: .55; cursor: not-allowed; }
.btn.secondary { background: transparent; color: var(--primary); }
.btn.secondary:hover { background: var(--surface-hover); }
.btn.ghost { background: transparent; border-color: transparent; color: var(--text-2); }
.btn.ghost:hover { background: var(--surface-hover); }
.btn.danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn.success { background: var(--success); border-color: var(--success); color: #06281b; }
.btn.sm { padding: 3px 10px; min-height: 28px; font-size: 13px; }

/* Forms */
.field { display: flex; flex-direction: column; gap: 4px; margin-bottom: 14px; }
.field > span { font-size: 13px; font-weight: 500; color: var(--text-2); }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
input[type=text], input[type=email], input[type=password], input[type=date], input[type=number], select, textarea {
  border: 1px solid var(--border); background: var(--surface); border-radius: var(--radius); padding: 7px 10px; min-height: 36px; width: 100%;
}
input:focus, select:focus, textarea:focus { border-color: var(--focus); outline: none; box-shadow: 0 0 0 2px color-mix(in srgb, var(--focus) 25%, transparent); }
textarea { min-height: 70px; resize: vertical; }
input[type=color] { width: 48px; height: 36px; padding: 2px; border: 1px solid var(--border); border-radius: var(--radius); background: var(--surface); }
.inline { display: inline-flex; width: auto; }
select.inline { width: auto; }
.check { display: flex; align-items: center; gap: 8px; cursor: pointer; padding: 3px 0; }
.check input { width: 16px; height: 16px; accent-color: var(--primary); }
.picker { border: 1px solid var(--border); border-radius: var(--radius); max-height: 150px; overflow-y: auto; padding: 6px 10px; background: var(--surface); }
.total { background: var(--info-bg); color: var(--info-text); border-radius: var(--radius); padding: 8px 12px; font-weight: 500; }
.total.err { background: var(--danger-bg); color: var(--danger-text); }
.form-error { color: var(--danger-text); background: var(--danger-bg); padding: 8px 12px; border-radius: var(--radius); margin-bottom: 12px; }

/* Tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th { text-align: left; font-weight: 600; font-size: 12px; color: var(--text-2); background: var(--surface-2); padding: 10px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; }
td { padding: 10px 12px; border-bottom: 1px solid var(--border-soft); vertical-align: middle; }
tr:hover td { background: var(--surface-hover); }
td.num, th.num { text-align: right; font-variant-numeric: tabular-nums; }
td.actions { white-space: nowrap; text-align: right; }
td[data-label="Dates"], td[data-label="Created"], td[data-label="Start"], td[data-label="End"], td[data-label="Date"], td[data-label="Usable from"], td[data-label="Usable until"] { white-space: nowrap; }
table.stack td.empty { display: block; text-align: center; }
td.actions .btn + .btn { margin-left: 6px; }
.empty { text-align: center; color: var(--muted); padding: 28px 12px; }
.muted { color: var(--muted); }
.sub { font-size: 12px; color: var(--muted); }
.pager { display: flex; justify-content: flex-end; align-items: center; gap: 8px; padding-top: 12px; font-size: 13px; color: var(--text-2); }

/* Badges + chips */
.badge { display: inline-block; padding: 2px 10px; border-radius: 12px; font-size: 12px; font-weight: 500; text-transform: capitalize; white-space: nowrap; }
.badge.pending { background: var(--warning-bg); color: var(--warning-text); }
.badge.approved { background: var(--success-bg); color: var(--success-text); }
.badge.rejected { background: var(--danger-bg); color: var(--danger-text); }
.badge.cancelled, .badge.off { background: var(--neutral-bg); color: var(--neutral-text); }
.badge.info { background: var(--info-bg); color: var(--info-text); }
.chip { display: inline-flex; align-items: center; gap: 6px; padding: 2px 10px 2px 8px; border-radius: 14px; font-size: 13px; font-weight: 500; white-space: nowrap;
  background: color-mix(in srgb, var(--c) 16%, var(--surface)); color: var(--text); border: 1px solid color-mix(in srgb, var(--c) 45%, transparent); }
.swatch { display: inline-block; width: 14px; height: 14px; border-radius: 3px; background: var(--c); vertical-align: middle; }

/* Tabs */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 16px; }
.tabs button { background: none; border: 0; padding: 10px 16px; cursor: pointer; color: var(--text-2); font-weight: 500; border-bottom: 3px solid transparent; margin-bottom: -1px; }
.tabs button.active { color: var(--primary); border-bottom-color: var(--primary); }

/* Modal */
.overlay { position: fixed; inset: 0; background: rgba(7, 24, 32, .55); display: flex; align-items: flex-start; justify-content: center; padding: 6vh 16px 16px; z-index: 50; overflow-y: auto; }
.modal { background: var(--surface); border-radius: var(--radius-card); box-shadow: var(--shadow-lg); width: 100%; max-width: 520px; }
.modal header { display: flex; justify-content: space-between; align-items: center; padding: 16px 20px; border-bottom: 1px solid var(--border-soft); }
.modal header h2 { margin: 0; }
.modal .body { padding: 18px 20px 6px; }
.modal footer { display: flex; justify-content: flex-end; gap: 8px; padding: 12px 20px 18px; }
.x { background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: var(--text-2); padding: 4px 8px; border-radius: var(--radius); }
.x:hover { background: var(--surface-hover); }

/* Toasts */
#toasts { position: fixed; right: 16px; bottom: 16px; display: flex; flex-direction: column; gap: 8px; z-index: 60; max-width: calc(100vw - 32px); }
.toast { background: var(--brand-navy); color: #fff; padding: 10px 16px; border-radius: var(--radius); box-shadow: var(--shadow-lg); border-left: 4px solid var(--success); }
.toast.err { border-left-color: var(--danger); }

/* Calendar */
.cal-head { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.cal-head .month { font-weight: 600; font-size: 18px; min-width: 170px; }
.cal { display: grid; grid-template-columns: repeat(7, minmax(0, 1fr)); border-left: 1px solid var(--border-soft); border-top: 1px solid var(--border-soft); border-radius: var(--radius-card); overflow: hidden; background: var(--surface); }
.cal .dow { background: var(--surface-2); font-size: 12px; font-weight: 600; color: var(--text-2); padding: 8px; border-right: 1px solid var(--border-soft); border-bottom: 1px solid var(--border-soft); }
.cal .day { min-height: 108px; padding: 4px 4px 6px; border-right: 1px solid var(--border-soft); border-bottom: 1px solid var(--border-soft); display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.cal .day.weekend { background: var(--weekend-bg); }
.cal .day.out { opacity: .45; }
.cal .day.holiday { background: var(--holiday-bg); }
.cal .num { font-size: 12px; font-weight: 600; color: var(--text-2); padding: 2px 4px; }
.cal .day.today .num { background: var(--primary); color: var(--primary-text); border-radius: 10px; align-self: flex-start; padding: 0 8px; }
.cal .hol { font-size: 11px; color: var(--warning-text); padding: 0 4px; line-height: 1.3; }
.ev { display: block; width: 100%; text-align: left; border: 0; border-left: 3px solid var(--c); background: color-mix(in srgb, var(--c) 22%, var(--surface)); color: var(--text); border-radius: 3px; font-size: 12px; padding: 1px 5px; cursor: pointer; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.ev.pending { background: repeating-linear-gradient(45deg, color-mix(in srgb, var(--c) 10%, var(--surface)) 0 6px, var(--surface) 6px 12px); border-left-style: dashed; opacity: .85; }
.legend { display: flex; gap: 14px; flex-wrap: wrap; font-size: 12px; color: var(--text-2); margin: 10px 0 0; }
.popover { position: fixed; z-index: 55; background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-card); box-shadow: var(--shadow-lg); padding: 14px 16px; width: 280px; max-width: calc(100vw - 32px); }
.popover dl { display: grid; grid-template-columns: auto 1fr; gap: 4px 12px; margin: 10px 0 0; font-size: 13px; }
.popover dt { color: var(--muted); }
.popover dd { margin: 0; }

/* Login */
.login-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 16px; background: linear-gradient(160deg, var(--brand-navy), #026c89 60%, var(--brand-blue)); }
.login { background: var(--surface); border-radius: var(--radius-card); box-shadow: var(--shadow-lg); padding: 28px; width: 100%; max-width: 380px; }
.login .brand { color: var(--text); padding: 0 0 18px; }
.login .btn { width: 100%; margin-top: 6px; }

/* Phone */
@media (max-width: 860px) {
  .shell { grid-template-columns: 1fr; }
  .topbar { display: flex; align-items: center; justify-content: space-between; gap: 8px; background: var(--sidebar-bg); color: #fff; padding: 10px 16px; position: sticky; top: 0; z-index: 30; }
  .topbar .brand { padding: 0; font-size: 16px; }
  .topbar button { background: none; border: 0; color: #fff; font-size: 22px; cursor: pointer; padding: 2px 8px; }
  .sidebar { position: fixed; inset: 0 30% 0 0; max-width: 280px; z-index: 40; transform: translateX(-100%); transition: transform .2s; }
  .sidebar.open { transform: none; box-shadow: var(--shadow-lg); }
  .main { padding: 16px 16px 40px; }
  .row { grid-template-columns: 1fr; gap: 0; }
  .cal .day { min-height: 64px; }
  .cal .ev { font-size: 0; padding: 0; height: 6px; border-left-width: 0; background: var(--c); }
  .cal .hol { display: none; }
  .cal .day.holiday .num::after { content: ' •'; color: var(--warning); }
  .cal .dow { padding: 6px 2px; text-align: center; }
  .cards { grid-template-columns: repeat(auto-fill, minmax(150px, 1fr)); }
  table.stack thead { display: none; }
  table.stack tr { display: block; border-bottom: 1px solid var(--border); padding: 8px 0; }
  table.stack td { display: flex; justify-content: space-between; gap: 12px; border: 0; padding: 4px 4px; text-align: right; }
  table.stack td::before { content: attr(data-label); color: var(--muted); font-size: 12px; text-align: left; }
  table.stack td.actions { justify-content: flex-end; }
  table.stack td.actions::before { content: none; }
  table.stack tr:hover td { background: none; }
}
