/* =========================================================
   OfficeHub - base application stylesheet
   Theme color is injected as --primary / --primary-rgb.
   ========================================================= */

:root {
  --primary: #0078d4;
  --primary-rgb: 0, 120, 212;
  --primary-dark: color-mix(in srgb, var(--primary) 82%, black);
  --primary-soft: rgba(var(--primary-rgb), 0.12);
  --primary-softer: rgba(var(--primary-rgb), 0.07);

  --bg: #f3f4f8;
  --surface: #ffffff;
  --surface-2: #f8f9fb;
  --surface-3: #eef0f4;
  --text: #1f2328;
  --muted: #667085;
  --border: #e3e6ec;
  --border-strong: #cdd2dc;

  --side-bg: #f7f8fa;
  --side-text: #3a3f47;
  --danger: #d13438;
  --danger-soft: #fdeaea;
  --ok: #107c10;
  --ok-soft: #e9f5e9;
  --warn: #c19c00;
  --warn-soft: #fdf6dd;

  --radius: 10px;
  --radius-lg: 14px;
  --shadow: 0 1px 3px rgba(16, 20, 30, .07), 0 4px 14px rgba(16, 20, 30, .05);
  --shadow-lg: 0 8px 32px rgba(16, 20, 30, .18);
  --mono: Consolas, "SF Mono", "Courier New", monospace;
}
html[data-theme="dark"] {
  --bg: #14171c;
  --surface: #1d2127;
  --surface-2: #22262e;
  --surface-3: #2a2f38;
  --text: #e6e9ee;
  --muted: #9aa3b0;
  --border: #323844;
  --border-strong: #3f4653;
  --side-bg: #171a20;
  --side-text: #c9ced7;
  --danger: #ff6b6e;
  --danger-soft: #3a2225;
  --ok: #6ccb5f;
  --ok-soft: #21301f;
  --warn: #e0b93b;
  --warn-soft: #342d18;
  --shadow: 0 1px 3px rgba(0, 0, 0, .4), 0 4px 14px rgba(0, 0, 0, .3);
  --shadow-lg: 0 10px 36px rgba(0, 0, 0, .55);
}

* { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", "Microsoft YaHei", sans-serif;
  font-size: 14px; color: var(--text); background: var(--bg);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
::-webkit-scrollbar { width: 10px; height: 10px; }
::-webkit-scrollbar-thumb { background: var(--border-strong); border-radius: 6px; border: 2px solid transparent; background-clip: content-box; }
::-webkit-scrollbar-track { background: transparent; }

/* ---------- app frame ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar {
  width: 236px; flex: 0 0 236px; background: var(--side-bg);
  border-right: 1px solid var(--border);
  display: flex; flex-direction: column; position: sticky; top: 0; height: 100vh; overflow: hidden;
}
.side-logo {
  display: flex; align-items: center; gap: 10px; padding: 18px 18px 14px;
  border-bottom: 1px solid var(--border); font-weight: 700; font-size: 16px; color: var(--text);
}
.side-logo img { width: 32px; height: 32px; object-fit: contain; border-radius: 8px; }
.logo-mark {
  width: 32px; height: 32px; border-radius: 9px; background: var(--primary);
  display: inline-grid; grid-template-columns: 1fr 1fr; gap: 3px; padding: 6px; flex: 0 0 auto;
}
.logo-mark i { background: #fff; border-radius: 2px; opacity: .95; }
.logo-mark i:nth-child(2), .logo-mark i:nth-child(3) { opacity: .6; }

.side-nav { flex: 1; overflow-y: auto; padding: 10px 10px 14px; }
.nav-group {
  font-size: 11px; font-weight: 700; letter-spacing: .6px; text-transform: uppercase;
  color: var(--muted); padding: 14px 10px 6px;
}
.nav-item {
  display: flex; align-items: center; gap: 10px; padding: 8px 10px; margin: 1px 0;
  border-radius: 8px; color: var(--side-text); font-weight: 500; position: relative;
}
.nav-item:hover { background: var(--primary-softer); text-decoration: none; }
.nav-item.active {
  background: var(--primary-soft); color: var(--primary); font-weight: 600;
}
.nav-item.active::before {
  content: ""; position: absolute; left: -10px; top: 7px; bottom: 7px; width: 3px;
  border-radius: 3px; background: var(--primary);
}
.nav-ico { width: 20px; text-align: center; font-size: 15px; }

.side-user {
  border-top: 1px solid var(--border); padding: 12px 14px;
  display: flex; align-items: center; gap: 10px;
}
.side-user-meta { flex: 1; min-width: 0; }
.side-user-meta b { display: block; font-size: 13px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.side-user-meta small { color: var(--muted); font-size: 11px; }
.side-logout {
  color: var(--muted); font-size: 16px; padding: 6px; border-radius: 6px;
}
.side-logout:hover { background: var(--danger-soft); color: var(--danger); text-decoration: none; }

.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar {
  height: 60px; background: var(--surface); border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 14px; padding: 0 22px;
  position: sticky; top: 0; z-index: 1100; /* above libs' internal z-indexes (frappe-gantt sticky header: 1000) */
}
.topbar-title h1 { font-size: 18px; font-weight: 650; }
.topbar-title p { font-size: 12px; color: var(--muted); margin-top: 1px; }
.topbar-actions { margin-left: auto; display: flex; align-items: center; gap: 10px; }
.nav-toggle { display: none; }

.content { padding: 22px; flex: 1; }
.app-foot {
  text-align: center; color: var(--muted); font-size: 12px; padding: 14px;
  border-top: 1px solid var(--border);
}

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px; padding: 8px 15px;
  border-radius: 8px; border: 1px solid var(--border-strong); background: var(--surface);
  color: var(--text); font-size: 13.5px; font-weight: 600; cursor: pointer; line-height: 1.2;
  transition: background .12s, border-color .12s, box-shadow .12s; user-select: none; white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: var(--border-strong); }
.btn:active { transform: translateY(1px); }
.btn-primary {
  background: var(--primary); border-color: var(--primary); color: #fff;
}
.btn-primary:hover { background: var(--primary-dark); border-color: var(--primary-dark); }
.btn-danger { background: var(--danger); border-color: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.92); }
.btn-ghost { border-color: transparent; background: transparent; }
.btn-ghost:hover { background: var(--primary-softer); }
.btn-sm { padding: 5px 10px; font-size: 12.5px; border-radius: 7px; }
.btn-lg { padding: 11px 22px; font-size: 15px; }
.btn[disabled] { opacity: .55; cursor: not-allowed; pointer-events: none; }
.icon-btn {
  border: none; background: transparent; width: 36px; height: 36px; border-radius: 8px;
  display: inline-flex; align-items: center; justify-content: center; cursor: pointer;
  color: var(--muted); font-size: 16px;
}
.icon-btn:hover { background: var(--primary-softer); color: var(--text); }
.icon-btn.sm { width: 28px; height: 28px; font-size: 13px; }
.btn svg, .icon-btn svg { width: 16px; height: 16px; }

/* ---------- forms ---------- */
.field { margin-bottom: 14px; }
.field > label { display: block; font-size: 12.5px; font-weight: 600; margin-bottom: 5px; color: var(--text); }
.field .hint { font-size: 11.5px; color: var(--muted); margin-top: 4px; }
.input, .select, .textarea {
  width: 100%; padding: 8px 11px; border-radius: 8px; font-size: 13.5px; font-family: inherit;
  border: 1px solid var(--border-strong); background: var(--surface); color: var(--text);
  outline: none; transition: border-color .12s, box-shadow .12s;
}
.input:focus, .select:focus, .textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px var(--primary-soft);
}
.textarea { resize: vertical; min-height: 80px; }
.input::placeholder, .textarea::placeholder { color: var(--muted); }
.select { appearance: none; background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M1 1l4 4 4-4' stroke='%23888' stroke-width='1.5' fill='none' stroke-linecap='round'/%3E%3C/svg%3E"); background-repeat: no-repeat; background-position: right 11px center; padding-right: 30px; }
.form-row { display: flex; gap: 12px; }
.form-row > * { flex: 1; min-width: 0; }
.checkbox-line { display: flex; align-items: center; gap: 8px; font-size: 13px; cursor: pointer; user-select: none; }
.checkbox-line input { width: 16px; height: 16px; accent-color: var(--primary); }
input[type="date"].input, input[type="time"].input, input[type="datetime-local"].input { min-width: 0; }
input[type="color"] { width: 40px; height: 34px; border: 1px solid var(--border-strong); border-radius: 8px; background: var(--surface); padding: 2px; cursor: pointer; }

.switch { position: relative; width: 42px; height: 24px; display: inline-block; flex: 0 0 auto; }
.switch input { opacity: 0; width: 0; height: 0; }
.switch .track {
  position: absolute; inset: 0; background: var(--border-strong); border-radius: 999px; transition: .15s; cursor: pointer;
}
.switch .track::after {
  content: ""; position: absolute; width: 18px; height: 18px; border-radius: 50%; background: #fff;
  top: 3px; left: 3px; transition: .15s; box-shadow: 0 1px 3px rgba(0,0,0,.25);
}
.switch input:checked + .track { background: var(--primary); }
.switch input:checked + .track::after { left: 21px; }

/* ---------- cards & panels ---------- */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg); box-shadow: var(--shadow); }
.card-h {
  padding: 14px 18px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 10px;
}
.card-h h3 { font-size: 14.5px; font-weight: 650; }
.card-h .spacer { flex: 1; }
.card-b { padding: 16px 18px; }
.panel-head { display: flex; align-items: center; gap: 10px; margin-bottom: 14px; flex-wrap: wrap; }
.panel-head h2 { font-size: 17px; }
.panel-head .spacer { flex: 1; }

/* ---------- stat cards ---------- */
.stat-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 14px; }
.stat-card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius-lg);
  padding: 16px 18px; display: flex; gap: 14px; align-items: center; box-shadow: var(--shadow);
}
.stat-ico {
  width: 44px; height: 44px; border-radius: 11px; display: flex; align-items: center; justify-content: center;
  font-size: 20px; background: var(--primary-soft); flex: 0 0 auto;
}
.stat-num { font-size: 24px; font-weight: 700; line-height: 1.1; }
.stat-label { font-size: 12.5px; color: var(--muted); margin-top: 2px; }
.stat-sub { font-size: 11.5px; color: var(--muted); margin-top: 3px; }

/* ---------- badges, chips, avatar, progress ---------- */
.badge {
  display: inline-flex; align-items: center; gap: 5px; padding: 2.5px 9px; font-size: 11.5px;
  font-weight: 600; border-radius: 999px; background: var(--surface-3); color: var(--text); white-space: nowrap;
}
.badge-primary { background: var(--primary-soft); color: var(--primary); }
.badge-ok { background: var(--ok-soft); color: var(--ok); }
.badge-warn { background: var(--warn-soft); color: var(--warn); }
.badge-danger { background: var(--danger-soft); color: var(--danger); }
.badge-dot { width: 7px; height: 7px; border-radius: 50%; background: currentColor; display: inline-block; }
.chip {
  display: inline-flex; align-items: center; gap: 6px; padding: 4px 11px; border-radius: 999px;
  border: 1px solid var(--border-strong); background: var(--surface); font-size: 12.5px; cursor: pointer; user-select: none;
}
.chip.on { background: var(--primary-soft); border-color: var(--primary); color: var(--primary); font-weight: 600; }
.avatar {
  width: 36px; height: 36px; border-radius: 50%; color: #fff; display: inline-flex;
  align-items: center; justify-content: center; font-size: 13px; font-weight: 700; flex: 0 0 auto;
}
.avatar-sm { width: 28px; height: 28px; font-size: 11px; }
.progress { height: 7px; background: var(--surface-3); border-radius: 999px; overflow: hidden; }
.progress > i { display: block; height: 100%; border-radius: 999px; background: var(--primary); }
.color-dot { width: 12px; height: 12px; border-radius: 4px; display: inline-block; flex: 0 0 auto; }

/* ---------- tables ---------- */
.table { width: 100%; border-collapse: collapse; font-size: 13.5px; }
.table th {
  text-align: left; font-size: 11.5px; text-transform: uppercase; letter-spacing: .4px;
  color: var(--muted); padding: 9px 12px; border-bottom: 1px solid var(--border); white-space: nowrap; font-weight: 700;
}
.table td { padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--primary-softer); }
.table .num { text-align: right; font-variant-numeric: tabular-nums; }

/* ---------- modal ---------- */
/* NOTE: keep above frappe-gantt's internal z-index 1000/1001 (sticky header, today marker) */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(15, 18, 25, .48); z-index: 2000;
  display: flex; align-items: flex-start; justify-content: center; padding: 46px 16px; overflow-y: auto;
  animation: fadeIn .14s ease;
}
.modal {
  background: var(--surface); border-radius: 14px; box-shadow: var(--shadow-lg);
  width: 100%; max-width: 520px; animation: slideUp .18s ease; border: 1px solid var(--border);
}
.modal.modal-lg { max-width: 760px; }
.modal.modal-xl { max-width: 1020px; }
.modal-h {
  padding: 15px 20px; border-bottom: 1px solid var(--border); display: flex; align-items: center; gap: 10px;
}
.modal-h h3 { font-size: 15.5px; flex: 1; }
.modal-x {
  border: none; background: transparent; font-size: 17px; cursor: pointer; color: var(--muted);
  width: 30px; height: 30px; border-radius: 7px;
}
.modal-x:hover { background: var(--surface-3); color: var(--text); }
.modal-b { padding: 18px 20px; max-height: calc(100vh - 250px); overflow-y: auto; }
.modal-f {
  padding: 13px 20px; border-top: 1px solid var(--border); display: flex; gap: 9px; justify-content: flex-end;
  background: var(--surface-2); border-radius: 0 0 14px 14px;
}
@keyframes fadeIn { from { opacity: 0; } }
@keyframes slideUp { from { opacity: 0; transform: translateY(14px); } }

/* ---------- toast ---------- */
.toast-stack { position: fixed; bottom: 20px; right: 20px; z-index: 2200; display: flex; flex-direction: column; gap: 9px; }
.toast {
  background: var(--surface); color: var(--text); border: 1px solid var(--border);
  border-left: 4px solid var(--primary); padding: 12px 16px; border-radius: 10px; box-shadow: var(--shadow-lg);
  min-width: 260px; max-width: 380px; font-size: 13.5px; animation: slideUp .18s ease; display: flex; gap: 9px; align-items: flex-start;
}
.toast.ok { border-left-color: var(--ok); }
.toast.err { border-left-color: var(--danger); }
.toast b { display: block; margin-bottom: 1px; }

/* ---------- dropdown ---------- */
.user-menu { position: relative; }
.user-chip {
  display: flex; align-items: center; gap: 8px; border: 1px solid transparent; background: transparent;
  padding: 4px 8px; border-radius: 999px; cursor: pointer; font-size: 13px; font-weight: 600; color: var(--text);
}
.user-chip:hover { background: var(--primary-softer); }
.user-chip .caret { color: var(--muted); font-size: 10px; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 6px); background: var(--surface);
  border: 1px solid var(--border); border-radius: 10px; box-shadow: var(--shadow-lg);
  min-width: 190px; padding: 5px; display: none; z-index: 90;
}
.dropdown.open { display: block; }
.dropdown a {
  display: flex; align-items: center; gap: 10px; padding: 8px 11px; border-radius: 7px;
  color: var(--text); font-size: 13.5px;
}
.dropdown a:hover { background: var(--primary-softer); text-decoration: none; }
.dropdown-sep { height: 1px; background: var(--border); margin: 5px 8px; }

/* ---------- tabs ---------- */
.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; flex-wrap: wrap; }
.tab {
  padding: 9px 16px; font-size: 13.5px; font-weight: 600; color: var(--muted); cursor: pointer;
  border-bottom: 2.5px solid transparent; margin-bottom: -1px; user-select: none; border-radius: 7px 7px 0 0;
}
.tab:hover { color: var(--text); background: var(--primary-softer); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

/* ---------- empty state ---------- */
.empty {
  text-align: center; padding: 46px 20px; color: var(--muted);
}
.empty .empty-ico { font-size: 40px; margin-bottom: 10px; opacity: .6; }
.empty p { font-size: 13.5px; margin-bottom: 14px; }

/* ---------- utilities ---------- */
.flex { display: flex; align-items: center; gap: 10px; }
.flex-wrap { flex-wrap: wrap; }
.spacer { flex: 1; }
.muted { color: var(--muted); }
.small { font-size: 12.5px; }
.right { text-align: right; }
.center { text-align: center; }
.mt-1 { margin-top: 8px; } .mt-2 { margin-top: 14px; } .mt-3 { margin-top: 20px; }
.mb-1 { margin-bottom: 8px; } .mb-2 { margin-bottom: 14px; }
.mono { font-family: var(--mono); }
.nowrap { white-space: nowrap; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.toolbar { display: flex; align-items: center; gap: 9px; flex-wrap: wrap; margin-bottom: 16px; }
.toolbar .search-box { position: relative; }
.toolbar .search-box .input { padding-left: 32px; width: 230px; }
.toolbar .search-box::before {
  content: "🔍"; position: absolute; left: 9px; top: 50%; transform: translateY(-50%); font-size: 12px; opacity: .55;
}

/* color swatch picker */
.swatches { display: flex; gap: 7px; flex-wrap: wrap; }
.swatch {
  width: 26px; height: 26px; border-radius: 8px; cursor: pointer; border: 2px solid transparent;
  display: inline-block; position: relative;
}
.swatch.on { border-color: var(--text); box-shadow: 0 0 0 2px var(--surface), 0 0 0 4px var(--primary); }
.swatch.custom input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; height: 100%; }

/* responsive */
@media (max-width: 960px) {
  .sidebar { position: fixed; z-index: 1300; left: 0; top: 0; transform: translateX(-100%); transition: transform .2s; height: 100vh; }
  .app.nav-open .sidebar { transform: none; box-shadow: var(--shadow-lg); }
  .nav-toggle { display: inline-flex; }
  .content { padding: 14px; }
  .grid-2 { grid-template-columns: 1fr; }
  .form-row { flex-direction: column; gap: 0; }
}
.app-nav-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.35); z-index: 1290; }

@media print {
  .sidebar, .topbar, .app-foot, .toast-stack, .no-print { display: none !important; }
  .content { padding: 0; }
  body { background: #fff; }
}
