/* Withdrawal & Settlement Console — standalone styling. Self-contained (no dependency on any other app). */

:root {
  --accent: #6d28d9;        /* violet — distinct from Hostel Dashboard's teal and the dispatcher board's indigo */
  --accent-dark: #5b21b6;
  --accent-soft: #ece5fb;
  --text: #1f2430;
  --muted: #6b7280;
  --border: #d7dae0;
  --bg: #f4f5f8;
  --card: #ffffff;
  --danger: #b00020;
  --warn-bg: #fff5e6;
  --warn-text: #8a5200;
  --warn-border: #e6a23c;
  --ok-bg: #d7ecd7;
  --ok-text: #1f5b1f;
  --font: 'Segoe UI', Tahoma, Arial, Helvetica, sans-serif;
}

* { box-sizing: border-box; }

/* the hidden attribute must always win, even over classes that set display */
[hidden] { display: none !important; }

body {
  margin: 0;
  padding: 20px;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
}

/* ---------- buttons ---------- */
.btn {
  font-family: var(--font);
  font-size: 13px;
  padding: 8px 14px;
  border-radius: 6px;
  border: 1px solid var(--border);
  background: #fff;
  color: var(--text);
  cursor: pointer;
}
.btn:hover { filter: brightness(0.97); }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-dark); }
.btn-danger { background: #fff; color: var(--danger); border-color: #e3b3bc; }
.btn-danger-solid { background: var(--danger); color: #fff; border-color: var(--danger); font-weight: 600; }
.btn-danger-solid:hover { background: #8a0018; }
.btn-small { font-size: 12px; padding: 5px 10px; }
.btn:disabled { opacity: 0.6; cursor: default; }
.btn-back {
  font-weight: 700; color: var(--accent-dark); border-color: var(--accent);
  background: var(--accent-soft);
}
.btn-back:hover { background: var(--accent); color: #fff; }

.icon-btn {
  border: none; background: none; cursor: pointer; font-size: 16px; line-height: 1;
  color: var(--muted); padding: 8px; border-radius: 6px;
}
.icon-btn:hover { background: #eef0f4; }
.icon-btn-danger { color: var(--danger); font-size: 18px; border: 1px solid #e3b3bc; }
.icon-btn-danger:hover { background: #fbe3e7; }

/* ---------- toolbar ---------- */
.toolbar {
  max-width: 1760px;
  margin: 0 auto 14px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 12px;
}
.toolbar-left { display: flex; align-items: center; gap: 12px; }
.toolbar-right { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.brand-mark {
  width: 44px; height: 44px;
  display: flex; align-items: center; justify-content: center;
  background: var(--accent); border-radius: 10px; font-size: 22px;
}
.brand-eyebrow { font-size: 11px; letter-spacing: 0.08em; color: var(--muted); font-weight: 600; }
.board-title { margin: 0; font-size: 22px; color: var(--text); }

.you-label { font-size: 13px; color: var(--muted); display: inline-flex; align-items: center; gap: 6px; }
.you-select, .filter-select {
  font-family: var(--font); font-size: 13px; padding: 7px 9px;
  border: 1px solid var(--border); border-radius: 6px; background: #fff;
}
.you-select { min-width: 140px; }

.role-badge {
  font-size: 11px; font-weight: 600; padding: 3px 9px; border-radius: 10px;
  border: 1px solid transparent;
}
.role-admin { background: #e7ddf7; color: #4a2f8a; }
.role-editor { background: #cdeef1; color: #145a63; }
.role-viewer { background: #eceef3; color: #555; }

/* ---------- sync banner ---------- */
.sync-banner {
  max-width: 1760px; margin: 0 auto 14px;
  padding: 9px 14px; border-radius: 8px; border: 1px solid var(--border); font-size: 13px;
}
.sync-banner-shared { background: #eaf6ea; border-color: #7cb97c; color: var(--ok-text); }
.sync-banner-local { background: #eef0f4; color: #555; }
.sync-banner-warn { background: var(--warn-bg); border-color: var(--warn-border); color: var(--warn-text); }

/* ---------- tabs ---------- */
.board { max-width: 1760px; margin: 0 auto; }
.tab-nav {
  display: flex; gap: 4px; flex-wrap: wrap; margin-bottom: 14px;
  border-bottom: 2px solid var(--border); padding-bottom: 0;
}
.tab-btn {
  font-family: var(--font); font-size: 14px; padding: 9px 16px; cursor: pointer;
  background: none; border: none; border-bottom: 3px solid transparent;
  color: var(--muted); font-weight: 600; margin-bottom: -2px;
}
.tab-btn:hover { color: var(--text); }
.tab-btn.tab-active { color: var(--accent); border-bottom-color: var(--accent); }

/* ---------- controls row ---------- */
.controls-row {
  display: flex; align-items: center; gap: 10px; flex-wrap: wrap; margin-bottom: 14px;
}
.controls-row .spacer { flex: 1 1 auto; }
.search-input {
  font-family: var(--font); font-size: 14px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 6px; min-width: 260px;
}

/* ---------- KPI tiles ---------- */
.kpi-row {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr));
  gap: 10px; margin-bottom: 16px;
}
.kpi {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 14px 16px;
}
.kpi-value { font-size: 26px; font-weight: 700; color: var(--text); }
.kpi-label { font-size: 12px; color: var(--muted); margin-top: 2px; }

/* ---------- chips ---------- */
.chip {
  font-size: 11px; font-weight: 600; padding: 3px 10px; border-radius: 12px; white-space: nowrap;
  display: inline-block;
}
.chip-area { background: var(--accent-soft); color: var(--accent-dark); }
.chip-ok { background: var(--ok-bg); color: var(--ok-text); }
.chip-warn { background: var(--warn-bg); color: var(--warn-text); border: 1px solid var(--warn-border); }
.chip-danger { background: #fbe3e7; color: var(--danger); }
.chip-muted { background: #eceef3; color: #555; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--border); border-radius: 10px; }
table.data-table { border-collapse: collapse; width: 100%; font-size: 13px; }
.data-table th {
  text-align: left; font-size: 11px; text-transform: uppercase; letter-spacing: 0.04em;
  color: var(--muted); padding: 10px 12px; border-bottom: 1px solid var(--border);
  white-space: nowrap; background: #fafbfc;
}
.data-table td { padding: 9px 12px; border-bottom: 1px solid #eef0f4; vertical-align: middle; }
.data-table tr:last-child td { border-bottom: none; }
.data-table th:last-child, .data-table td:last-child:not([colspan]) { width: 1%; white-space: nowrap; }
.data-table tr.row-click { cursor: pointer; }
.data-table tr.row-click:hover td { background: #f7fbfa; }
.worker-name-cell { font-weight: 600; }
.subtle { color: var(--muted); font-size: 12px; }
.row-actions { display: flex; gap: 6px; flex-wrap: wrap; }

/* Withdrawals/Settlements tables can run wide - Passport Name (the identity anchor)
   stays pinned to the left edge as the rest scrolls underneath it. */
.flat-table .col-sticky { position: sticky; left: 0; z-index: 2; background: var(--card); box-shadow: 2px 0 4px -2px rgba(0,0,0,0.15); }
.flat-table th.col-sticky { background: #fafbfc; z-index: 3; }

/* Columns show/hide picker */
.col-picker { position: relative; }
.col-picker-panel {
  position: absolute; top: 100%; right: 0; margin-top: 6px; background: var(--card);
  border: 1px solid var(--border); border-radius: 8px; padding: 10px 12px; min-width: 220px;
  max-height: 320px; overflow-y: auto; box-shadow: 0 6px 20px rgba(0,0,0,0.12); z-index: 20;
}
.col-picker-row { display: flex; align-items: center; gap: 8px; padding: 5px 0; font-size: 13px; white-space: nowrap; }
.col-picker-divider { border-top: 1px solid var(--border); margin: 2px 0 4px; }
.multiline-cell { white-space: pre-line; max-width: 260px; }

.empty-state { text-align: center; color: var(--muted); font-size: 14px; padding: 28px 0; }

/* ---------- worker profile ---------- */
.profile-head {
  background: var(--card); border: 1px solid var(--border); border-radius: 10px;
  padding: 16px 18px; margin-bottom: 14px;
}
.profile-title { font-size: 22px; font-weight: 800; margin: 0 0 8px; }
.profile-grid {
  display: grid; grid-template-columns: repeat(auto-fit, minmax(200px, 1fr)); gap: 10px 18px;
}
.profile-item { display: flex; flex-direction: column; gap: 2px; }
.profile-label {
  font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted);
}
.profile-value { font-size: 14px; font-weight: 500; }
.profile-section { margin-bottom: 18px; }
.profile-section h3 { font-size: 15px; margin: 0 0 8px; display: flex; align-items: center; gap: 8px; }
.profile-totals { font-size: 12px; color: var(--muted); font-weight: 500; }
.profile-totals b { color: var(--text); }

/* ---------- forms / modals ---------- */
.modal { position: fixed; inset: 0; z-index: 50; display: flex; align-items: center; justify-content: center; }
.modal[hidden] { display: none; }
.modal-backdrop { position: absolute; inset: 0; background: rgba(20, 24, 34, 0.45); }
.modal-card {
  position: relative; background: var(--card); border-radius: 12px; width: min(560px, 94vw);
  max-height: 90vh; overflow-y: auto; padding: 18px 20px; box-shadow: 0 12px 40px rgba(0, 0, 0, 0.25);
}
.modal-card-wide { width: min(760px, 96vw); }
.modal-head { display: flex; align-items: center; justify-content: space-between; margin-bottom: 12px; }
.modal-title { margin: 0; font-size: 18px; }

.form-grid { display: grid; grid-template-columns: repeat(2, 1fr); gap: 12px; }
.form-field { display: flex; flex-direction: column; gap: 4px; font-size: 12px; color: var(--muted); }
.form-field > span { font-weight: 700; }
.form-field-wide { grid-column: 1 / -1; }
.form-field input, .form-field select, .form-field textarea {
  font-family: var(--font); font-size: 14px; color: var(--text);
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px; background: #fff;
}
.form-field input:disabled, .form-field select:disabled, .form-field textarea:disabled {
  background: #f2f3f6; color: var(--muted); cursor: not-allowed;
}
.form-field-locked span::after { content: ' 🔒'; }
.record-lock-banner {
  grid-column: 1 / -1; background: var(--warn-bg); border: 1px solid var(--warn-border);
  color: var(--warn-text); border-radius: 8px; padding: 10px 14px; font-size: 13px; font-weight: 600;
}
/* Still its own full-width grid row (form-field-wide), but the box itself is capped to a
   single column's width — half the row minus half the gap — to match a normal field like
   Status instead of stretching edge to edge. */
.attachment-field { gap: 6px; width: calc(50% - 6px); max-width: calc(50% - 6px); }
.attachment-list { display: flex; flex-direction: column; gap: 4px; margin-bottom: 4px; }
.attachment-item {
  display: flex; align-items: center; gap: 8px; font-size: 12px;
  border: 1px solid var(--border); border-radius: 6px; padding: 4px 8px; background: #fff;
}
.attachment-item a { color: var(--accent-dark); flex: 1 1 auto; word-break: break-all; }
.attachment-field input[type="file"] {
  /* .form-field is a column flexbox, which stretches children to fill its width by
     default — override that so this sizes to its own content (button + filename) instead
     of spanning the full field width edge-to-edge. */
  align-self: flex-start;
  font-size: 12px; padding: 4px; border: 1px solid var(--border); border-radius: 6px;
  background: #fff; max-width: 100%;
}

/* ---------- activity / audit log ---------- */
.audit-list {
  display: flex; flex-direction: column; gap: 4px; max-height: 130px; overflow-y: auto;
  border: 1px solid var(--border); border-radius: 6px; padding: 6px 8px; background: #fafbfc;
}
.audit-entry { font-size: 11px; line-height: 1.5; color: var(--text); }
.audit-entry b { font-weight: 600; }

.vacation-toggle { display: flex; gap: 6px; flex-wrap: wrap; align-items: center; }
.vacation-btn {
  font-family: var(--font); font-size: 13px; padding: 6px 12px; border-radius: 6px;
  border: 1px solid var(--border); background: #fff; cursor: pointer;
}
.vacation-btn:disabled { opacity: 0.6; cursor: default; }
.vacation-btn.vacation-active-yes { background: var(--ok-bg); border-color: #7cb97c; color: var(--ok-text); font-weight: 600; }
.vacation-btn.vacation-active-no { background: #fbe3e7; border-color: #e3a3af; color: var(--danger); font-weight: 600; }
.vacation-icon { font-size: 15px; }
.form-actions { margin-top: 14px; display: flex; gap: 8px; flex-wrap: wrap; }
.form-error { color: var(--danger); font-size: 13px; margin-top: 8px; }

.pin-row { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.pin-input {
  font-family: var(--font); font-size: 14px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 6px; flex: 1 1 160px;
}
.pin-error { color: var(--danger); font-size: 13px; }
.pin-state { color: var(--muted); font-size: 13px; margin: 4px 0 8px; }

.manage-section { margin-bottom: 18px; }
.manage-section-title { font-weight: 600; font-size: 13px; margin-bottom: 8px; color: var(--text); }
.user-list { display: flex; flex-direction: column; gap: 8px; margin-bottom: 10px; }
.user-row-wrap { border: 1px solid var(--border); border-radius: 8px; padding: 8px 10px; }
.user-row { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }
.user-row-name { flex: 1 1 140px; font-size: 14px; font-weight: 600; }
.user-nat-scope {
  margin-top: 8px; padding-top: 8px; border-top: 1px solid #eef0f4;
  display: flex; flex-wrap: wrap; gap: 10px; align-items: center; font-size: 12px; color: var(--muted);
}
.user-nat-scope label { display: inline-flex; align-items: center; gap: 4px; white-space: nowrap; color: var(--text); }
.user-role-select {
  font-family: var(--font); font-size: 12px; padding: 4px 6px;
  border: 1px solid var(--border); border-radius: 6px; background: #fff;
}
.user-contact-input {
  font-family: var(--font); font-size: 12px; padding: 5px 7px;
  border: 1px solid var(--border); border-radius: 6px; width: 160px;
}
.add-user-row { display: flex; gap: 8px; flex-wrap: wrap; }
.add-user-name {
  font-family: var(--font); font-size: 14px; padding: 8px 10px;
  border: 1px solid var(--border); border-radius: 6px; flex: 1 1 140px;
}
.manage-empty { color: var(--muted); font-size: 13px; padding: 6px 0; }

.picklist-group { margin-bottom: 14px; }
.picklist-group h4 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); margin: 0 0 6px; }
.picklist-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 8px; }
.picklist-chip {
  display: inline-flex; align-items: center; gap: 4px; font-size: 12px;
  background: var(--accent-soft); color: var(--accent-dark); border-radius: 12px; padding: 3px 6px 3px 10px;
}
.picklist-chip button {
  border: none; background: none; cursor: pointer; color: var(--accent-dark); font-size: 13px; line-height: 1; padding: 0 2px;
}
.picklist-add-row { display: flex; gap: 8px; flex-wrap: wrap; }
.picklist-bulk { margin-top: 8px; font-size: 12px; }
.picklist-bulk summary { cursor: pointer; color: var(--accent-dark); font-weight: 600; }
.picklist-bulk textarea {
  display: block; width: 100%; margin-top: 6px; font-family: var(--font); font-size: 13px;
  padding: 8px 10px; border: 1px solid var(--border); border-radius: 6px;
}
.picklist-bulk button { margin-top: 6px; }

/* ---------- permissions matrix ---------- */
.perm-editor { background: var(--card); border: 1px solid var(--border); border-radius: 10px; padding: 14px 16px; margin-bottom: 14px; }
.perm-editor h3 { margin: 0 0 4px; font-size: 15px; }
.perm-editor .subtle { margin-bottom: 10px; }
.perm-forms { display: grid; grid-template-columns: repeat(auto-fit, minmax(260px, 1fr)); gap: 14px; }
.perm-form-group h4 { font-size: 12px; text-transform: uppercase; letter-spacing: 0.03em; color: var(--muted); margin: 0 0 6px; }
.perm-field-list { display: flex; flex-direction: column; gap: 4px; }
.perm-field-row { display: flex; align-items: center; gap: 8px; font-size: 13px; }

@media (max-width: 720px) {
  body { padding: 10px; font-size: 15px; }

  /* toolbar: brand row and identity controls each get their own full-width row instead
     of competing for horizontal space */
  .toolbar { gap: 10px; }
  .toolbar-left, .toolbar-right { width: 100%; }
  .toolbar-right { justify-content: flex-start; }
  .you-select { min-width: 0; flex: 1 1 120px; }
  .board-title { font-size: 19px; }

  .sync-banner { font-size: 12px; }

  /* tabs: scroll sideways instead of wrapping into a cramped multi-row grid */
  .tab-nav { flex-wrap: nowrap; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .tab-btn { flex: 0 0 auto; padding: 10px 14px; }

  /* controls row: search/filters/add button each take the full width and stack, so
     they're easy to tap instead of tiny inline dropdowns */
  .controls-row { flex-direction: column; align-items: stretch; }
  .controls-row .spacer { display: none; }
  .search-input, .filter-select, #btn-add-withdrawal, #btn-add-settlement { width: 100%; min-width: 0; }

  .form-grid { grid-template-columns: 1fr; }
  .profile-grid { grid-template-columns: 1fr; }
  .modal-card, .modal-card-wide { width: 100vw; max-height: 100vh; height: 100%; border-radius: 0; }

  /* bigger touch targets for the small controls that pack tightly on desktop */
  .icon-btn { padding: 10px; }
  .vacation-btn { padding: 9px 14px; }
  .perm-field-row { padding: 4px 0; font-size: 14px; }

  /* data tables become stacked cards: each row is a bordered block, each cell a
     label/value line (the label comes from the data-label attribute render.js sets on
     every <td>) — a plain table can't fit this many columns on a phone screen no matter
     how much it scrolls, so this trades the grid layout for one that actually fits. */
  .table-wrap { overflow-x: visible; border: none; background: none; }
  .data-table thead { display: none; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table tr {
    background: var(--card); border: 1px solid var(--border); border-radius: 10px;
    padding: 10px 12px; margin-bottom: 10px;
  }
  .data-table td {
    display: flex; justify-content: space-between; align-items: flex-start; gap: 12px;
    padding: 7px 0; border-bottom: 1px solid #eef0f4; text-align: right; width: auto;
  }
  .data-table td:last-child { border-bottom: none; }
  .data-table td:empty { display: none; }
  .data-table td::before {
    content: attr(data-label); font-size: 11px; font-weight: 600; text-transform: uppercase;
    letter-spacing: 0.03em; color: var(--muted); text-align: left; flex: 0 0 auto;
  }
  .data-table td[data-label=""]::before { content: none; }
  .multiline-cell { max-width: 62%; text-align: right; }
  .flat-table .col-sticky { position: static; box-shadow: none; }
  .col-picker-panel { left: 0; right: auto; width: 100%; box-sizing: border-box; }
}
