:root {
  --ink: #151C2C;
  --ink-soft: #2A3450;
  --paper: #F6F5F2;
  --paper-deep: #EDEBE5;
  --line: #DEDBD2;
  --amber: #D98E2B;
  --amber-soft: #F3D9AE;
  --present: #2F7D5C;
  --present-soft: #DCEEE4;
  --late: #C77B22;
  --late-soft: #F5E3C7;
  --absent: #B5453B;
  --absent-soft: #F4DEDB;
  --slate: #6B7280;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  height: 100%;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 14px;
}

button, input, select, textarea { font-family: inherit; }
button:focus-visible, input:focus-visible, select:focus-visible {
  outline: 2px solid var(--amber);
  outline-offset: 1px;
}

.app {
  display: grid;
  grid-template-columns: 260px 1fr 320px;
  height: 100vh;
  min-height: 640px;
}

/* Sidebar */
.sidebar {
  background: var(--ink);
  color: #EDEBE5;
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  min-height: 0;
}
.brand { display: flex; align-items: center; gap: 10px; margin-bottom: 28px; }
.brand-mark {
  width: 34px; height: 34px; border-radius: 8px;
  background: var(--amber); color: var(--ink);
  display: flex; align-items: center; justify-content: center;
  font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 13px;
}
.brand-title { font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: 16px; }
.brand-sub { font-size: 11.5px; color: #9AA3BF; }

.nav { display: flex; flex-direction: column; gap: 4px; margin-bottom: 24px; }
.nav-btn {
  text-align: left; background: transparent; border: none; color: #C7CCE0;
  padding: 9px 12px; border-radius: 8px; font-size: 13.5px; cursor: pointer;
}
.nav-btn.active { background: #232C46; color: #fff; font-weight: 600; }

.side-label {
  font-size: 11px; letter-spacing: 0.06em; text-transform: uppercase;
  color: #7C84A3; margin-bottom: 8px; padding-left: 4px;
}
.employee-list { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 3px; min-height: 0; }
.employee-row {
  display: flex; align-items: center; gap: 9px; background: transparent; border: none;
  padding: 8px; border-radius: 8px; color: #EDEBE5; cursor: pointer; text-align: left; width: 100%;
}
.employee-row.active { background: #232C46; }
.dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; background: var(--amber); }
.dot.all { background: var(--ink-soft); }
.employee-name { font-size: 13px; font-weight: 500; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.employee-role { font-size: 11px; color: #8B92AC; }
.employee-hours { font-size: 11.5px; color: #B7BEDA; font-variant-numeric: tabular-nums; margin-left: auto; }
.employee-row-text { flex: 1; min-width: 0; }

.save-state {
  margin-top: 12px; display: flex; align-items: center; gap: 7px;
  font-size: 11.5px; color: #8B92AC; padding-top: 12px; border-top: 1px solid #2A3450;
}
.save-dot { width: 6px; height: 6px; border-radius: 50%; background: var(--present); }
.save-dot.saving { background: var(--late); }

.account-bar { margin-top: 10px; padding-top: 10px; border-top: 1px solid #2A3450; }
.account-username { display: block; font-size: 12px; font-weight: 600; color: #C7CCE0; margin-bottom: 6px; }
.account-links { display: flex; gap: 12px; }
.account-link {
  background: none; border: none; padding: 0; font-size: 11.5px; font-weight: 600;
  color: #8B92AC; cursor: pointer; text-decoration: none; font-family: inherit;
}
.account-link:hover { color: #EDEBE5; }

/* Main */
.main { padding: 28px 32px; overflow-y: auto; min-width: 0; }
.header { display: flex; justify-content: space-between; align-items: flex-end; margin-bottom: 20px; flex-wrap: wrap; gap: 12px; }
.h1 { font-family: 'Space Grotesk', sans-serif; font-size: 26px; font-weight: 600; margin: 0; }
.sub { font-size: 13px; color: var(--slate); margin: 4px 0 0; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.icon-btn { width: 32px; height: 32px; border-radius: 8px; border: 1px solid var(--line); background: #fff; cursor: pointer; font-size: 14px; color: var(--ink); }
.today-btn { border: 1px solid var(--line); background: #fff; border-radius: 8px; padding: 7px 12px; font-size: 13px; cursor: pointer; color: var(--ink); }
.month-select, .year-select {
  width: auto; padding: 7px 10px; font-size: 13px; font-weight: 600; cursor: pointer;
}
.month-select { min-width: 118px; }
.year-select { min-width: 80px; }
.primary-btn { background: var(--ink); color: #fff; border: none; border-radius: 8px; padding: 9px 16px; font-size: 13px; font-weight: 600; cursor: pointer; }
.small-primary-btn { background: var(--ink); color: #fff; border: none; border-radius: 7px; padding: 6px 12px; font-size: 12.5px; font-weight: 600; cursor: pointer; }
.secondary-btn { background: transparent; color: var(--ink); border: 1px solid var(--line); border-radius: 8px; padding: 9px 16px; font-size: 13px; font-weight: 600; cursor: pointer; }

.calendar-wrap { background: #fff; border: 1px solid var(--line); border-radius: 14px; overflow: visible; }
.week-row { display: grid; grid-template-columns: repeat(7, 1fr); border-bottom: 1px solid var(--line); border-top-left-radius: 13px; border-top-right-radius: 13px; overflow: hidden; }
.week-head { padding: 10px 0; text-align: center; font-size: 11.5px; font-weight: 600; color: var(--slate); text-transform: uppercase; letter-spacing: 0.04em; }
.grid { display: grid; grid-template-columns: repeat(7, 1fr); }
.empty-cell {
  min-height: 84px; border-right: 1px solid var(--paper-deep); border-bottom: 1px solid var(--paper-deep);
  background: var(--paper);
}
.cell {
  min-height: 84px; border-right: 1px solid var(--paper-deep); border-bottom: 1px solid var(--paper-deep);
  background: #fff; position: relative;
  border: none; padding: 8px; display: flex; flex-direction: column; align-items: flex-start;
  gap: 6px; cursor: pointer; width: 100%; text-align: left;
}
.cell-icons { position: absolute; top: 6px; right: 6px; display: flex; gap: 3px; z-index: 1; }
.cell-icon {
  width: 15px; height: 15px; border-radius: 50%;
  background: var(--ink); color: #fff;
  font-size: 9px; font-weight: 700;
  display: flex; align-items: center; justify-content: center;
  line-height: 1; cursor: help; position: relative;
}
.cell-icon.note { font-style: italic; font-family: Georgia, 'Times New Roman', serif; }
.cell-icon.visit { background: #4A5568; font-size: 9px; }
.cell-icon.payment { background: var(--present); }
.cell-icon.equipment { background: #8B5E34; }
.cell-icon[data-tooltip]:hover::after {
  content: attr(data-tooltip);
  position: absolute; top: 20px; right: 0;
  background: var(--ink); color: #fff;
  padding: 6px 10px; border-radius: 7px;
  font-size: 11px; font-weight: 600; line-height: 1.4;
  white-space: normal; word-break: break-word; text-align: left;
  width: max-content; max-width: 200px;
  box-shadow: 0 6px 16px rgba(21,28,44,0.25);
  z-index: 30; pointer-events: none;
}
.cell-icon[data-tooltip]:hover::before {
  content: ""; position: absolute; top: 15px; right: 4px;
  border: 5px solid transparent; border-bottom-color: var(--ink);
  z-index: 30; pointer-events: none;
}
.cell.selected { background: var(--amber-soft); }
.cell.today { box-shadow: inset 0 0 0 2px var(--amber); }
.cell.absent { background: var(--absent-soft); }
.cell.absent.selected { background: var(--absent-soft); box-shadow: inset 0 0 0 2px var(--absent); }
.cell-date { font-size: 13px; font-weight: 600; color: var(--ink); }
.cell-absent-label { font-size: 11.5px; font-weight: 700; color: var(--absent); text-transform: uppercase; letter-spacing: 0.03em; }
.cell-line { display: flex; align-items: center; gap: 5px; font-size: 11px; color: var(--ink); line-height: 1.3; }
.cell-dot { width: 7px; height: 7px; border-radius: 50%; flex-shrink: 0; }
.cell-count { font-weight: 700; }
.cell-hours { color: var(--slate); font-variant-numeric: tabular-nums; white-space: nowrap; }

/* Day panel */
.day-panel { border-left: 1px solid var(--line); background: #fff; padding: 26px 20px; display: flex; flex-direction: column; min-height: 0; }
.day-panel-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 12px; gap: 10px; }
.day-panel-actions { display: flex; gap: 8px; margin-bottom: 16px; }
.secondary-btn.small { padding: 6px 10px; font-size: 11.5px; border-radius: 7px; }
.day-subheading { font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: 0.04em; color: var(--slate); margin: 14px 0 8px; }
.mini-card { border: 1px solid var(--line); border-radius: 9px; padding: 10px; background: var(--paper); margin-bottom: 8px; }
.mini-card-top { display: flex; justify-content: space-between; align-items: center; }
.mini-card-title { font-size: 12.5px; font-weight: 600; }
.mini-card-note { font-size: 11.5px; color: var(--slate); margin-top: 4px; font-style: italic; }
.day-panel-date { font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: 16px; text-transform: capitalize; }
.day-panel-sub { font-size: 12px; color: var(--slate); margin-top: 2px; }
.day-entries { flex: 1; overflow-y: auto; display: flex; flex-direction: column; gap: 10px; min-height: 0; }
.empty-state { font-size: 12.5px; color: var(--slate); line-height: 1.5; padding: 8px 2px; }

.entry-card { border: 1px solid var(--line); border-radius: 10px; padding: 12px; background: var(--paper); }
.entry-top { display: flex; justify-content: space-between; align-items: center; margin-bottom: 8px; }
.status-pill { font-size: 11px; font-weight: 600; padding: 3px 8px; border-radius: 999px; }
.entry-actions { display: flex; gap: 10px; }
.link-btn, .link-btn-danger { background: none; border: none; font-size: 11.5px; cursor: pointer; font-weight: 600; padding: 0; }
.link-btn { color: var(--ink); }
.link-btn-danger { color: var(--absent); }
.entry-employee { font-size: 13.5px; font-weight: 600; }
.entry-meta { font-size: 12px; color: var(--slate); margin-top: 2px; }
.entry-project { font-size: 12px; color: var(--ink); margin-top: 6px; font-weight: 500; }
.entry-note { font-size: 12px; color: var(--slate); margin-top: 6px; font-style: italic; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0; background: rgba(21,28,44,0.45);
  display: none; align-items: center; justify-content: center; z-index: 50;
}
.modal-overlay.open { display: flex; }
.modal { background: #fff; border-radius: 14px; width: 500px; max-width: 92vw; max-height: 86vh; display: flex; flex-direction: column; }
.modal-header { display: flex; justify-content: space-between; align-items: center; padding: 18px 20px; border-bottom: 1px solid var(--line); }
.modal-title { font-family: 'Space Grotesk', sans-serif; font-size: 16px; font-weight: 600; margin: 0; }
.close-btn { background: none; border: none; font-size: 22px; cursor: pointer; color: var(--slate); line-height: 1; }
.modal-body { padding: 18px 20px; display: flex; flex-direction: column; gap: 14px; overflow-y: auto; }
.modal-footer { display: flex; justify-content: flex-end; gap: 10px; padding: 16px 20px; border-top: 1px solid var(--line); }
.field { display: flex; flex-direction: column; gap: 5px; }
.field-row { display: flex; gap: 12px; }
.field-label { font-size: 12px; font-weight: 600; color: var(--slate); }
.input { border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; font-size: 13.5px; color: var(--ink); background: #fff; width: 100%; }
.status-row { display: flex; gap: 8px; }
.status-chip { border: none; border-radius: 999px; padding: 7px 14px; font-size: 12.5px; font-weight: 600; cursor: pointer; }

.field-label-row { display: flex; justify-content: space-between; align-items: center; }
.quick-select { display: flex; gap: 6px; }
.quick-btn {
  border: 1px solid var(--line); background: #fff; color: var(--slate);
  border-radius: 999px; padding: 3px 9px; font-size: 11px; font-weight: 600; cursor: pointer;
}
.quick-btn:hover { border-color: var(--ink); color: var(--ink); }
.employee-checklist {
  border: 1px solid var(--line); border-radius: 8px; padding: 4px;
  max-height: 180px; overflow-y: auto; display: flex; flex-direction: column; gap: 1px;
}
.employee-check-row {
  display: flex; align-items: center; gap: 8px; padding: 7px 8px; border-radius: 6px; cursor: pointer;
}
.employee-check-row:hover { background: var(--paper); }
.employee-check-row input { accent-color: var(--ink); width: 15px; height: 15px; flex-shrink: 0; }
.employee-check-name { font-size: 13px; font-weight: 500; flex: 1; }
.modal-error { font-size: 11.5px; color: var(--absent); margin-top: 6px; }
.single-employee-name {
  border: 1px solid var(--line); border-radius: 8px; padding: 9px 10px; font-size: 13.5px;
  font-weight: 600; background: var(--paper);
}

/* Config view */
.config-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 24px; }
.sub-nav { display: flex; gap: 6px; margin: 20px 0 20px; border-bottom: 1px solid var(--line); }
.sub-nav-btn {
  background: transparent; border: none; padding: 9px 14px; font-size: 13px; font-weight: 600;
  color: var(--slate); cursor: pointer; border-bottom: 2px solid transparent; margin-bottom: -1px;
}
.sub-nav-btn.active { color: var(--ink); border-bottom-color: var(--ink); }

.fert-card { border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 16px; margin-bottom: 12px; }
.fert-top { display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.fert-name { font-family: 'Space Grotesk', sans-serif; font-size: 16px; font-weight: 600; }
.fert-meta { font-size: 12px; color: var(--slate); margin-top: 3px; }
.fert-qty { text-align: right; }
.fert-qty-value { font-size: 20px; font-weight: 700; color: var(--ink); font-variant-numeric: tabular-nums; }
.fert-qty-label { font-size: 10.5px; color: var(--slate); text-transform: uppercase; letter-spacing: 0.03em; }
.fert-actions { display: flex; gap: 8px; margin-top: 12px; }
.fert-history { margin-top: 12px; padding-top: 12px; border-top: 1px solid var(--paper-deep); display: none; }
.fert-history.open { display: block; }
.fert-history-row { display: flex; justify-content: space-between; align-items: center; padding: 6px 0; font-size: 12.5px; }
.fert-history-row + .fert-history-row { border-top: 1px dashed var(--paper-deep); }
.fert-history-note { color: var(--slate); font-style: italic; }

.nav-group-toggle { display: flex; justify-content: space-between; align-items: center; }
.nav-caret { font-size: 10px; transition: transform 0.15s; }
.nav-caret.open { transform: rotate(180deg); }
.nav-subgroup { display: flex; flex-direction: column; gap: 2px; padding-left: 10px; }
.nav-btn.nav-sub { font-size: 12.5px; padding: 7px 12px; color: #B7BEDA; }
.nav-btn.nav-sub.active { background: #232C46; color: #fff; font-weight: 600; }

.ac-item-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.ac-item-row .input { margin-bottom: 0; }
.ac-item-subtotal { min-width: 90px; text-align: right; font-weight: 600; font-size: 13px; color: var(--ink); }
.ac-remove-btn {
  background: none; border: none; color: var(--absent); font-size: 18px; cursor: pointer;
  width: 26px; height: 26px; flex-shrink: 0; line-height: 1;
}
.ac-total-row {
  display: flex; justify-content: space-between; align-items: center;
  margin-top: 14px; padding-top: 12px; border-top: 1px solid var(--line);
  font-size: 15px; font-weight: 700; color: var(--ink);
}
.purchase-card { border: 1px solid var(--line); border-radius: 12px; background: #fff; padding: 16px; margin-bottom: 12px; }
.purchase-top { display: flex; justify-content: space-between; align-items: flex-start; }
.purchase-ref { font-family: 'Space Grotesk', sans-serif; font-weight: 700; font-size: 14px; color: var(--ink); }
.purchase-date { font-size: 12px; color: var(--slate); margin-top: 2px; }
.purchase-items { margin-top: 10px; font-size: 12.5px; color: var(--ink); }
.purchase-items div { padding: 3px 0; display: flex; justify-content: space-between; }
.purchase-note { font-size: 12px; color: var(--slate); font-style: italic; margin-top: 6px; }
.purchase-attachment { display: inline-block; margin-top: 8px; font-size: 12px; color: var(--amber); font-weight: 600; text-decoration: none; }
.config-card { background: #fff; border: 1px solid var(--line); border-radius: 14px; padding: 20px; }
.config-title { font-family: 'Space Grotesk', sans-serif; font-size: 16px; font-weight: 600; margin: 0 0 14px; }
.config-form { display: flex; gap: 8px; margin-bottom: 16px; flex-wrap: wrap; }
.config-list { display: flex; flex-direction: column; gap: 8px; }
.config-row { display: flex; justify-content: space-between; align-items: center; padding: 10px 12px; background: var(--paper); border-radius: 9px; }
.config-row-right { display: flex; align-items: center; gap: 14px; }
.total-badge { font-size: 11.5px; color: var(--slate); font-variant-numeric: tabular-nums; }
.type-badge {
  display: inline-block; margin-left: 8px; font-size: 10px; font-weight: 700;
  text-transform: uppercase; letter-spacing: 0.03em; padding: 2px 7px; border-radius: 999px;
  vertical-align: middle;
}

.calendar-legend { display: flex; align-items: center; gap: 16px; margin-bottom: 14px; flex-wrap: wrap; }
.legend-item { display: flex; align-items: center; gap: 7px; font-size: 12.5px; font-weight: 600; color: var(--ink); cursor: pointer; }
.legend-swatch {
  width: 22px; height: 22px; border-radius: 7px; border: 1px solid var(--line);
  padding: 0; cursor: pointer; background: none;
}
.legend-swatch::-webkit-color-swatch-wrapper { padding: 2px; }
.legend-swatch::-webkit-color-swatch { border-radius: 5px; border: none; }

@media (prefers-reduced-motion: reduce) { * { transition: none !important; } }

/* ---------------------------------------------------------------------- */
/* Mobile topbar + sidebar drawer (hidden on desktop)                     */
/* ---------------------------------------------------------------------- */
.mobile-topbar { display: none; }
.mobile-menu-btn {
  width: 36px; height: 36px; border-radius: 8px; border: none;
  background: #232C46; color: #fff; font-size: 17px; cursor: pointer; flex-shrink: 0;
}
.mobile-topbar-brand { display: flex; align-items: center; gap: 9px; }
.mobile-topbar-title { font-family: 'Space Grotesk', sans-serif; font-weight: 600; font-size: 15px; }
.sidebar-backdrop { display: none; }

@media (max-width: 900px) {
  html, body { font-size: 14px; }
  .app {
    grid-template-columns: 1fr;
    height: auto;
    min-height: 100vh;
    align-content: start;
  }
  .mobile-topbar {
    display: flex; align-items: center; gap: 12px;
    padding: 12px 16px; background: var(--ink); color: #EDEBE5;
    position: sticky; top: 0; z-index: 80;
  }
  .sidebar {
    position: fixed; top: 0; left: 0; bottom: 0; width: 82vw; max-width: 300px;
    transform: translateX(-100%); transition: transform 0.22s ease;
    z-index: 100; overflow-y: auto; padding: 20px 16px;
  }
  .sidebar.open { transform: translateX(0); box-shadow: 8px 0 24px rgba(0,0,0,0.25); }
  .sidebar .brand { margin-bottom: 22px; }
  .sidebar-backdrop {
    display: block; position: fixed; inset: 0; background: rgba(15,19,30,0.5);
    z-index: 90; opacity: 0; pointer-events: none; transition: opacity 0.2s ease;
  }
  .sidebar-backdrop.open { opacity: 1; pointer-events: auto; }

  .main { padding: 16px; overflow-x: hidden; overflow-y: visible; }
  .day-panel { border-left: none; border-top: 1px solid var(--line); padding: 18px 16px; overflow-y: visible; }

  .header { flex-direction: column; align-items: stretch; gap: 12px; }
  .header-actions { flex-wrap: wrap; gap: 6px; }
  .header-actions > * { flex: 0 0 auto; }
  .month-select { min-width: 100px; flex: 1; }
  .year-select { min-width: 68px; }
  .primary-btn#newEntryBtn { width: 100%; order: 10; margin-top: 4px; }

  .calendar-legend { gap: 10px; row-gap: 8px; }
  .legend-item { font-size: 11.5px; }
  .legend-swatch { width: 19px; height: 19px; }

  .week-head { font-size: 9.5px; padding: 7px 0; }
  .cell, .empty-cell { min-height: 54px; }
  .cell { padding: 5px; gap: 3px; }
  .cell-date { font-size: 11.5px; }
  .cell-line { font-size: 9px; gap: 3px; }
  .cell-hours { display: none; }
  .cell-icons { top: 3px; right: 3px; }
  .cell-icon { width: 13px; height: 13px; font-size: 8px; }

  .config-grid { grid-template-columns: 1fr; }
  .config-form { flex-direction: column; align-items: stretch; }
  .config-form > * { max-width: none !important; width: 100%; }
  .config-row { flex-wrap: wrap; gap: 8px; }
  .config-row-right { flex-wrap: wrap; gap: 8px; }

  .field-row { flex-direction: column; gap: 12px; }
  .modal { width: 92vw; max-height: 88vh; }
  .quick-select { flex-wrap: wrap; }
  .field-label-row { flex-wrap: wrap; gap: 6px; }
  .status-row { flex-wrap: wrap; }

  .ac-item-row { flex-wrap: wrap; }
  .ac-item-row .ac-name { flex: 1 1 100%; }
  .ac-item-row .ac-price, .ac-item-row .ac-qty { flex: 1 1 auto; min-width: 90px; }
  .ac-item-subtotal { min-width: auto; flex: 1 1 100%; text-align: left; }

  .day-panel-actions { flex-wrap: wrap; }
  .day-panel-actions .secondary-btn.small { flex: 1 1 auto; }

  .fert-top { flex-direction: column; align-items: flex-start; gap: 8px; }
  .fert-qty { text-align: left; }
  .fert-actions { flex-wrap: wrap; }
  .fert-actions .link-btn-danger { margin-left: 0 !important; }

  .purchase-top { flex-direction: column; align-items: flex-start; gap: 8px; }

  .employee-list { max-height: 220px; }
}

@media (max-width: 420px) {
  .brand-title { font-size: 15px; }
  .h1 { font-size: 21px; }
  .cell, .empty-cell { min-height: 46px; }
  .today-btn { padding: 7px 9px; font-size: 12px; }
}
