:root {
  --dark: #2e0b0f; --dark-2: #5c1419; --accent: #9e1f26; --accent-dark: #7a161c; --tint: #fbeeee;
  --text: #2a2224; --muted: #6b6062; --bg: #f7f4f4; --card: #fff; --border: #e8dfe0;
  --ok: #1e7f4c; --ok-bg: #e5f5ec; --warn: #9a6400; --warn-bg: #fff3d9; --bad: #b42318; --bad-bg: #fde8e7;
  --info: #1d5fa8; --info-bg: #e6f0fb; --radius: 10px; --shadow: 0 1px 3px rgba(46,11,15,.08);
}
* { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body { margin: 0; font: 15px/1.5 "Inter", system-ui, -apple-system, "Segoe UI", Roboto, sans-serif; color: var(--text); background: var(--bg); }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }
h1, h2, h3, h4 { color: var(--dark); line-height: 1.25; margin: 0 0 .5em; }
h1 { font-size: 1.45rem; } h2 { font-size: 1.15rem; } h3 { font-size: 1rem; }
small, .muted { color: var(--muted); }
.nowrap { white-space: nowrap; }
.right { text-align: right; }
.mt { margin-top: 1rem; } .mb0 { margin-bottom: 0; }

/* Layout */
.layout { display: grid; grid-template-columns: 240px 1fr; min-height: 100vh; }
.sidebar { background: var(--dark); color: #e9d6d8; padding: 1rem .75rem; position: sticky; top: 0; height: 100vh; overflow-y: auto; display: flex; flex-direction: column; }
.brand { display: flex; align-items: center; gap: .6rem; padding: .25rem .5rem 1rem; color: #fff; text-decoration: none !important; }
.brand img { width: 38px; height: 38px; background: #fff; border-radius: 50%; padding: 2px; }
.brand b { display: block; font-size: .95rem; letter-spacing: .02em; }
.brand small { color: #d9b5b8; font-size: .7rem; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a { color: #f0dfe0; padding: .55rem .75rem; border-radius: 8px; display: flex; gap: .6rem; align-items: center; text-decoration: none; }
.nav a:hover { background: rgba(255,255,255,.08); }
.nav a.on { background: var(--accent); color: #fff; }
.nav .sep { margin: .75rem .75rem .25rem; font-size: .7rem; text-transform: uppercase; letter-spacing: .1em; color: #b78f93; }
.me { margin-top: auto; padding: .75rem; border-top: 1px solid rgba(255,255,255,.1); font-size: .85rem; }
.me b { color: #fff; display: block; }
.me a, .me button { color: #f2b8bb; }
.main { padding: 1.25rem 1.75rem 3rem; min-width: 0; }
.topbar { display: flex; align-items: center; justify-content: space-between; gap: 1rem; flex-wrap: wrap; margin-bottom: 1rem; }
.topbar .crumbs { font-size: .85rem; color: var(--muted); margin-bottom: .15rem; }
.topbar h1 { margin: 0; }
.actions { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }
.btn.menu-btn { display: none; }

/* Cards / grid */
.card { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1.1rem 1.25rem; box-shadow: var(--shadow); margin-bottom: 1rem; }
.card > h2:first-child, .card > h3:first-child { margin-top: 0; }
.card-head { display: flex; justify-content: space-between; align-items: center; gap: .5rem; margin-bottom: .75rem; }
.card-head h2, .card-head h3 { margin: 0; }
.grid { display: grid; gap: 1rem; }
.g2 { grid-template-columns: repeat(2, minmax(0, 1fr)); }
.g3 { grid-template-columns: repeat(3, minmax(0, 1fr)); }
.g4 { grid-template-columns: repeat(4, minmax(0, 1fr)); }
.stat { background: var(--card); border: 1px solid var(--border); border-radius: var(--radius); padding: 1rem 1.1rem; box-shadow: var(--shadow); }
.stat b { display: block; font-size: 1.6rem; color: var(--dark); line-height: 1.2; }
.stat span { color: var(--muted); font-size: .85rem; }
.stat.alert b { color: var(--bad); }
dl.kv { display: grid; grid-template-columns: max-content 1fr; gap: .35rem 1rem; margin: 0; }
dl.kv dt { color: var(--muted); }
dl.kv dd { margin: 0; }

/* Buttons */
.btn { display: inline-flex; align-items: center; gap: .35rem; background: var(--accent); color: #fff !important; border: 1px solid var(--accent); padding: .5rem .95rem; border-radius: 8px; font: inherit; font-weight: 600; font-size: .9rem; cursor: pointer; text-decoration: none !important; min-height: 38px; }
.btn:hover { background: var(--accent-dark); }
.btn.ghost { background: #fff; color: var(--accent) !important; border-color: var(--border); }
.btn.ghost:hover { border-color: var(--accent); }
.btn.sm { padding: .3rem .65rem; font-size: .8rem; min-height: 30px; }
.btn.danger { background: #fff; color: var(--bad) !important; border-color: #f0c7c4; }
.btn.ok { background: var(--ok); border-color: var(--ok); }
.btn[disabled] { opacity: .5; cursor: not-allowed; }
.linkbtn { background: none; border: 0; padding: 0; font: inherit; color: var(--accent); cursor: pointer; }
form.inline { display: inline; }

/* Forms */
label { display: block; font-weight: 600; font-size: .85rem; color: var(--dark); margin-bottom: .25rem; }
input[type=text], input[type=email], input[type=password], input[type=number], input[type=date], input[type=time], input[type=url], input[type=tel], input:not([type]), select, textarea {
  width: 100%; font: inherit; padding: .5rem .65rem; border: 1px solid #d9cdce; border-radius: 8px; background: #fff; color: var(--text); min-height: 38px;
}
input:focus, select:focus, textarea:focus { outline: 2px solid rgba(158,31,38,.35); border-color: var(--accent); }
textarea { resize: vertical; }
.field { margin-bottom: .9rem; }
.field .help { font-size: .78rem; color: var(--muted); margin-top: .2rem; }
.field .err, .errorlist { color: var(--bad); font-size: .82rem; margin: .2rem 0 0; padding: 0; list-style: none; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 0 1rem; }
.form-grid .full { grid-column: 1 / -1; }
.checks { display: grid; grid-template-columns: repeat(auto-fill, minmax(200px, 1fr)); gap: .25rem .75rem; max-height: 220px; overflow: auto; border: 1px solid var(--border); border-radius: 8px; padding: .5rem .75rem; background: #fff; }
.checks label { font-weight: 400; display: flex; gap: .4rem; align-items: center; margin: 0; color: var(--text); }
.checks ul { list-style: none; padding: 0; margin: 0; display: contents; }
.checks li { margin: 0; }
input[type=checkbox] { width: 16px; height: 16px; accent-color: var(--accent); }
.filters { display: flex; gap: .5rem; flex-wrap: wrap; align-items: end; margin-bottom: 1rem; }
.filters input, .filters select { width: auto; min-width: 150px; }
.alert { padding: .7rem 1rem; border-radius: 8px; margin-bottom: 1rem; border: 1px solid; }
.alert.error { background: var(--bad-bg); border-color: #f5c2bd; color: var(--bad); }
.alert.success { background: var(--ok-bg); border-color: #b6e2c8; color: var(--ok); }
.alert.info, .alert.warning { background: var(--warn-bg); border-color: #f1d79c; color: var(--warn); }

/* Tables */
.table-wrap { overflow-x: auto; background: #fff; border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
th, td { padding: .55rem .75rem; text-align: left; border-bottom: 1px solid var(--border); vertical-align: top; }
th { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); background: #fcf9f9; font-weight: 700; white-space: nowrap; }
tbody tr:hover { background: #fdf8f8; }
tr:last-child td { border-bottom: 0; }
td.num, th.num { text-align: right; white-space: nowrap; font-variant-numeric: tabular-nums; }
tfoot td { font-weight: 700; background: #fcf9f9; }
.empty { text-align: center; color: var(--muted); padding: 2rem 1rem; }

/* Badges */
.badge { display: inline-block; padding: .1rem .55rem; border-radius: 999px; font-size: .75rem; font-weight: 700; white-space: nowrap; background: #eee; color: #444; }
.b-active, .b-present, .b-completed, .b-accepted, .b-receive { background: var(--ok-bg); color: var(--ok); }
.b-in_progress, .b-sent, .b-late, .b-transfer { background: var(--info-bg); color: var(--info); }
.b-on_hold, .b-half_day, .b-reopened, .b-draft, .b-expired, .b-high { background: var(--warn-bg); color: var(--warn); }
.b-absent, .b-rejected, .b-urgent, .b-use, .b-return, .b-adjust_out, .b-inactive, .b-overdue { background: var(--bad-bg); color: var(--bad); }
.b-todo, .b-planned, .b-leave, .b-superseded, .b-low, .b-normal { background: #f0eced; color: #5c5254; }
.b-super_admin, .b-admin { background: var(--dark); color: #fff; }
.b-manager { background: var(--tint); color: var(--accent); }
.b-supervisor { background: #eef0f6; color: #3f4a6b; }

/* Tabs */
.tabs { display: flex; gap: .25rem; border-bottom: 1px solid var(--border); margin-bottom: 1rem; overflow-x: auto; }
.tabs a { padding: .6rem .9rem; color: var(--muted); border-bottom: 2px solid transparent; white-space: nowrap; text-decoration: none; font-weight: 600; font-size: .9rem; }
.tabs a.on { color: var(--accent); border-bottom-color: var(--accent); }

/* Progress */
.progress { height: 8px; background: #efe6e7; border-radius: 99px; overflow: hidden; min-width: 80px; }
.progress > i { display: block; height: 100%; background: var(--ok); }

/* Kanban */
.board { display: grid; grid-template-columns: repeat(4, minmax(220px, 1fr)); gap: .75rem; overflow-x: auto; }
.col { background: #efe8e9; border-radius: var(--radius); padding: .6rem; min-height: 120px; }
.col h3 { font-size: .8rem; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); display: flex; justify-content: space-between; margin: .2rem .3rem .6rem; }
.tcard { display: block; background: #fff; border: 1px solid var(--border); border-radius: 8px; padding: .6rem .7rem; margin-bottom: .5rem; color: var(--text); box-shadow: var(--shadow); text-decoration: none !important; }
.tcard:hover { border-color: var(--accent); }
.tcard b { display: block; font-size: .9rem; color: var(--dark); }
.tcard .meta { font-size: .75rem; color: var(--muted); margin-top: .3rem; display: flex; gap: .4rem; flex-wrap: wrap; align-items: center; }
.tcard.overdue { border-left: 3px solid var(--bad); }

/* Activity feed */
.feed { list-style: none; padding: 0; margin: 0; }
.feed li { padding: .75rem 0; border-bottom: 1px solid var(--border); }
.feed li:last-child { border-bottom: 0; }
.feed .who { font-size: .8rem; color: var(--muted); }
.feed img { max-width: 260px; max-height: 220px; border-radius: 8px; margin-top: .4rem; display: block; border: 1px solid var(--border); }

/* Attendance */
.att-table td { vertical-align: middle; }
.att-table select, .att-table input { min-height: 34px; padding: .3rem .4rem; }
.att-table input[type=time] { width: 125px; }
.seg { display: inline-flex; border: 1px solid #d9cdce; border-radius: 8px; overflow: hidden; }
.seg label { margin: 0; font-weight: 600; font-size: .78rem; padding: .35rem .55rem; cursor: pointer; color: var(--muted); border-right: 1px solid #eadfe0; background: #fff; }
.seg label:last-child { border-right: 0; }
.seg input { position: absolute; opacity: 0; pointer-events: none; }
.seg input:checked + span { color: #fff; }
.seg label:has(input:checked) { background: var(--accent); color: #fff; }
.month-grid td, .month-grid th { padding: .3rem .25rem; text-align: center; font-size: .75rem; }
.month-grid td:first-child, .month-grid th:first-child { text-align: left; padding-left: .6rem; white-space: nowrap; }
.month-grid .we { background: #faf6f6; }
.cell-present, .cell-late { color: var(--ok); font-weight: 700; }
.cell-half_day { color: var(--warn); font-weight: 700; }
.cell-absent { color: var(--bad); font-weight: 700; }
.cell-leave { color: var(--info); font-weight: 700; }
.cal { display: grid; grid-template-columns: repeat(7, 1fr); gap: 4px; }
.cal .d { background: #fff; border: 1px solid var(--border); border-radius: 6px; min-height: 62px; padding: .3rem .4rem; font-size: .75rem; }
.cal .d.out { opacity: .35; }
.cal .h { font-size: .7rem; text-transform: uppercase; color: var(--muted); text-align: center; }

/* Estimate builder */
.est-section { border: 1px solid var(--border); border-radius: var(--radius); background: #fff; margin-bottom: 1rem; }
.est-section .sec-head { display: flex; gap: .5rem; align-items: center; padding: .6rem .75rem; background: #fcf6f6; border-bottom: 1px solid var(--border); border-radius: var(--radius) var(--radius) 0 0; }
.est-section .sec-head input { font-weight: 700; max-width: 360px; }
.lines { width: 100%; }
.lines td { padding: .35rem .4rem; vertical-align: middle; }
.lines input { min-height: 34px; padding: .3rem .45rem; }
.lines .w-qty { width: 90px; } .lines .w-unit { width: 70px; } .lines .w-price { width: 115px; } .lines .w-tax { width: 70px; } .lines .w-amt { width: 120px; }
.picker { position: relative; }
.picker .results { position: absolute; z-index: 20; left: 0; right: 0; top: 100%; background: #fff; border: 1px solid var(--border); border-radius: 8px; box-shadow: 0 8px 24px rgba(0,0,0,.12); max-height: 260px; overflow: auto; display: none; }
.picker .results div { padding: .45rem .6rem; cursor: pointer; font-size: .85rem; }
.picker .results div:hover, .picker .results div.hl { background: var(--tint); }
.picker .tag { font-size: .7rem; color: var(--muted); }
.totals { margin-left: auto; max-width: 380px; }
.totals td { padding: .3rem .5rem; }
.totals .grand td { font-size: 1.1rem; font-weight: 800; color: var(--dark); border-top: 2px solid var(--dark); }
.sticky-bar { position: sticky; bottom: 0; background: rgba(247,244,244,.96); padding: .75rem 0; display: flex; gap: .5rem; justify-content: flex-end; border-top: 1px solid var(--border); margin-top: 1rem; }

/* Auth pages */
.auth { min-height: 100vh; display: grid; place-items: center; padding: 1.5rem; background: linear-gradient(135deg, var(--dark), var(--dark-2)); }
.auth .box { background: #fff; border-radius: 14px; padding: 2rem; width: 100%; max-width: 400px; box-shadow: 0 20px 60px rgba(0,0,0,.3); }
.auth .logo { display: flex; align-items: center; gap: .7rem; margin-bottom: 1.25rem; }
.auth .logo img { width: 48px; }
.auth .logo b { color: var(--accent); display: block; font-size: 1.05rem; }
.qr svg { width: 200px; height: 200px; display: block; margin: .5rem 0; }
.secret { font-family: ui-monospace, Menlo, monospace; background: var(--tint); padding: .3rem .5rem; border-radius: 6px; word-break: break-all; }
.temp-pass { font-family: ui-monospace, Menlo, monospace; font-size: 1.5rem; letter-spacing: .08em; background: var(--tint); color: var(--dark); padding: .75rem 1rem; border-radius: 8px; display: inline-block; }

/* Responsive */
@media (max-width: 900px) {
  .layout { grid-template-columns: 1fr; }
  .sidebar { position: fixed; inset: 0 auto 0 0; width: 260px; z-index: 50; transform: translateX(-100%); transition: transform .2s; }
  body.nav-open .sidebar { transform: none; box-shadow: 0 0 0 100vmax rgba(0,0,0,.4); }
  .btn.menu-btn { display: inline-flex; }
  .main { padding: 1rem; }
  .g2, .g3, .g4, .form-grid { grid-template-columns: 1fr; }
  .g4.stats { grid-template-columns: repeat(2, 1fr); }
  .board { grid-template-columns: repeat(4, 80vw); }
}
@media print { .sidebar, .topbar .actions, .menu-btn { display: none !important; } .layout { display: block; } }
