/* GOTEC dashboard — light, original theme. */
:root {
  --bg: #f4f6f8;
  --surface: #ffffff;
  --surface-2: #f8fafb;
  --border: #e2e7ec;
  --text: #17212b;
  --text-2: #55636f;
  --text-3: #7b8892;
  --accent: #0f6e6a;
  --accent-hover: #0b5753;
  --accent-soft: #e3f2f1;
  --danger: #b4322c;
  --danger-soft: #fbe9e8;
  --warn: #8a5a00;
  --warn-soft: #fdf2dc;
  --info: #2457a6;
  --info-soft: #e6eefb;
  --ok: #1d6b38;
  --ok-soft: #e3f4e8;
  --neutral-soft: #eef1f4;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow: 0 1px 2px rgba(23, 33, 43, .05), 0 2px 8px rgba(23, 33, 43, .04);
  --font: system-ui, -apple-system, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; } /* never let a display rule override the hidden attribute */
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 15px/1.5 var(--font);
}
h1, h2, h3 { margin: 0; line-height: 1.25; }
button, input, select, textarea { font: inherit; color: inherit; }
a { color: var(--accent); }

.proto-banner {
  background: #fff7e0; color: #5f4300; border-bottom: 1px solid #f0dca5;
  padding: 8px 16px; font-size: 13.5px; text-align: center;
}

/* ---------- Layout ---------- */
.shell { display: flex; min-height: calc(100vh - 38px); }
.sidebar {
  width: 228px; flex: 0 0 228px; background: var(--surface);
  border-right: 1px solid var(--border); padding: 20px 14px;
  display: flex; flex-direction: column; gap: 20px;
  position: sticky; top: 0; height: 100vh;
}
.brand { display: flex; align-items: center; gap: 10px; padding: 0 8px; }
.brand-mark {
  width: 32px; height: 32px; border-radius: 9px; background: var(--accent); color: #fff;
  display: grid; place-items: center; font-weight: 700;
}
.brand-name { font-weight: 700; letter-spacing: .06em; }
.nav { display: flex; flex-direction: column; gap: 2px; }
.nav a {
  text-decoration: none; color: var(--text-2); padding: 9px 12px; border-radius: var(--radius-sm);
  font-weight: 500; white-space: nowrap;
}
.nav a:hover { background: var(--surface-2); color: var(--text); }
.nav a[aria-current="page"] { background: var(--accent-soft); color: var(--accent); }
.sidebar-foot { margin-top: auto; }
.storage-note { font-size: 12px; color: var(--text-3); margin: 8px 4px 0; }

.main { flex: 1; min-width: 0; padding: 28px 32px 48px; outline: none; }
.page-head { display: flex; align-items: flex-start; justify-content: space-between; gap: 16px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { font-size: 24px; }
.page-sub { margin: 4px 0 0; color: var(--text-2); font-size: 14px; }
.page-actions { display: flex; gap: 8px; flex-wrap: wrap; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid transparent; border-radius: var(--radius-sm); padding: 9px 16px;
  font-weight: 600; font-size: 14px; cursor: pointer; text-decoration: none; min-height: 40px;
}
.btn-primary { background: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-hover); }
.btn-ghost { background: var(--surface); border-color: var(--border); color: var(--text); }
.btn-ghost:hover { background: var(--surface-2); }
.btn-danger { background: var(--danger); color: #fff; }
.btn-danger:hover { filter: brightness(.93); }
.btn-small { padding: 5px 10px; min-height: 32px; font-size: 13px; }
.btn-block { width: 100%; }
.btn:focus-visible, .nav a:focus-visible, select:focus-visible, input:focus-visible, textarea:focus-visible, .icon-btn:focus-visible {
  outline: 3px solid rgba(15, 110, 106, .35); outline-offset: 1px;
}
.icon-btn {
  border: 0; background: transparent; font-size: 26px; line-height: 1; width: 40px; height: 40px;
  border-radius: 8px; cursor: pointer; color: var(--text-2);
}
.icon-btn:hover { background: var(--surface-2); }

/* ---------- Cards ---------- */
.section { margin-bottom: 28px; }
.section-head { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin-bottom: 12px; flex-wrap: wrap; }
.section-head h2 { font-size: 17px; }
.scope { font-size: 13px; color: var(--text-3); }
.cards { display: grid; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); gap: 14px; }
.card {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 16px 18px; box-shadow: var(--shadow); min-width: 0;
}
.card-label { font-size: 13px; color: var(--text-2); font-weight: 500; }
.card-value { font-size: 26px; font-weight: 700; margin-top: 6px; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.card-value.is-null { color: var(--text-3); }
.card-note { font-size: 12.5px; color: var(--text-3); margin-top: 4px; }
.card-note.warn { color: var(--warn); }

.period-bar {
  display: flex; gap: 10px; align-items: flex-end; flex-wrap: wrap;
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  padding: 12px 14px; margin-bottom: 18px;
}
.period-bar .field { margin: 0; min-width: 150px; }
.period-label { font-size: 14px; color: var(--text-2); padding-bottom: 9px; }
.period-label strong { color: var(--text); }

/* ---------- Toolbar ---------- */
.toolbar { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 14px; }
.toolbar input[type="search"] { flex: 1 1 220px; }
.toolbar select { flex: 0 1 220px; }
.result-count { font-size: 13px; color: var(--text-3); margin: -4px 0 10px; }

/* ---------- Tables ---------- */
.table-wrap {
  background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
  box-shadow: var(--shadow); overflow-x: auto;
}
.data-table { width: 100%; border-collapse: collapse; font-size: 14px; }
.data-table th {
  text-align: left; font-size: 12px; text-transform: uppercase; letter-spacing: .04em;
  color: var(--text-3); font-weight: 600; padding: 11px 14px; background: var(--surface-2);
  border-bottom: 1px solid var(--border); white-space: nowrap;
}
.data-table td { padding: 11px 14px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.data-table tbody tr:last-child td { border-bottom: 0; }
.data-table tbody tr:hover td { background: #fbfcfd; }
.data-table .num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }
.data-table .actions { text-align: right; white-space: nowrap; }
.data-table .actions .btn + .btn { margin-left: 6px; }
.cell-main { font-weight: 600; overflow-wrap: anywhere; }
.cell-sub { font-size: 12px; color: var(--text-3); }
.cell-wrap { max-width: 320px; overflow-wrap: anywhere; }
.muted { color: var(--text-3); }
.overdue { color: var(--danger); font-weight: 600; }

.pipeline-table td:first-child { width: 60%; }

/* ---------- Badges & status selects ---------- */
.badge {
  display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 12.5px; font-weight: 600;
  white-space: nowrap; background: var(--neutral-soft); color: var(--text-2);
}
[data-tone="ok"] { background: var(--ok-soft); color: var(--ok); }
[data-tone="info"] { background: var(--info-soft); color: var(--info); }
[data-tone="warn"] { background: var(--warn-soft); color: var(--warn); }
[data-tone="danger"] { background: var(--danger-soft); color: var(--danger); }
[data-tone="accent"] { background: var(--accent-soft); color: var(--accent); }
.status-select {
  border: 1px solid transparent; border-radius: 999px; padding: 4px 26px 4px 10px; font-size: 13px; font-weight: 600;
  background-color: var(--neutral-soft); cursor: pointer; max-width: 100%;
  appearance: none; -webkit-appearance: none;
  background-image: linear-gradient(45deg, transparent 50%, currentColor 50%), linear-gradient(135deg, currentColor 50%, transparent 50%);
  background-position: calc(100% - 13px) 55%, calc(100% - 9px) 55%;
  background-size: 4px 4px; background-repeat: no-repeat;
}

/* ---------- Empty states ---------- */
.empty {
  background: var(--surface); border: 1px dashed #cfd7de; border-radius: var(--radius);
  padding: 36px 20px; text-align: center; color: var(--text-2);
}
.empty h3 { font-size: 16px; color: var(--text); margin-bottom: 6px; }
.empty p { margin: 0 auto 14px; max-width: 440px; }

/* ---------- Forms ---------- */
.field { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; min-width: 0; }
.field label, .field .label { font-size: 13px; font-weight: 600; color: var(--text-2); }
.req { color: var(--danger); }
.field input[type="text"], .field input[type="email"], .field input[type="tel"], .field input[type="url"],
.field input[type="date"], .field input[type="number"], .field select, .field textarea,
.toolbar input, .toolbar select {
  width: 100%; border: 1px solid #cdd5dc; border-radius: var(--radius-sm); padding: 9px 11px;
  background: #fff; font-size: 16px; min-height: 42px;
}
.field textarea { min-height: 76px; resize: vertical; }
.field .hint { font-size: 12px; color: var(--text-3); }
.field .error { font-size: 12.5px; color: var(--danger); display: none; }
.field.has-error input, .field.has-error select, .field.has-error textarea { border-color: var(--danger); background: #fffafa; }
.field.has-error .error { display: block; }
.check { flex-direction: row; align-items: flex-start; gap: 10px; flex-wrap: wrap; }
.check input { width: 20px; height: 20px; margin: 2px 0 0; flex: 0 0 auto; accent-color: var(--accent); }
.check label { flex: 1 1 200px; font-weight: 500; color: var(--text); }
.check .error { flex-basis: 100%; }

fieldset.group { border: 1px solid var(--border); border-radius: var(--radius); padding: 14px 16px 2px; margin: 0 0 16px; min-width: 0; }
fieldset.group legend { font-weight: 700; font-size: 14px; padding: 0 6px; }
fieldset.group .group-note { font-size: 12.5px; color: var(--text-2); margin: -4px 0 12px; }
fieldset.group.attention { border-color: var(--warn); background: #fffcf4; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.form-grid .span-2 { grid-column: 1 / -1; }
.id-line { font-size: 12.5px; color: var(--text-3); margin: 0 0 14px; }

/* ---------- Dialogs ---------- */
.dialog {
  border: 0; border-radius: 16px; padding: 0; width: min(760px, calc(100vw - 32px));
  max-height: calc(100vh - 48px); box-shadow: 0 20px 60px rgba(0, 0, 0, .2); color: var(--text);
}
.dialog-small { width: min(480px, calc(100vw - 32px)); }
.dialog::backdrop { background: rgba(23, 33, 43, .45); }
.dialog form { display: flex; flex-direction: column; max-height: calc(100vh - 48px); }
.dialog-head { display: flex; align-items: center; justify-content: space-between; padding: 16px 20px; border-bottom: 1px solid var(--border); }
.dialog-head h2 { font-size: 18px; }
.dialog-body { padding: 18px 20px; overflow-y: auto; }
.dialog-foot { display: flex; gap: 10px; justify-content: flex-end; align-items: center; padding: 14px 20px; border-top: 1px solid var(--border); flex-wrap: wrap; }
.form-error { margin: 0 auto 0 0; color: var(--danger); font-size: 13.5px; }
.backup-block + .backup-block { border-top: 1px solid var(--border); margin-top: 18px; padding-top: 18px; }
.backup-block h3 { font-size: 15px; margin-bottom: 6px; }
.backup-block p { margin: 0 0 12px; color: var(--text-2); }
.file-label { display: inline-block; position: relative; }
.file-label input { position: absolute; inset: 0; opacity: 0; cursor: pointer; width: 100%; }
.import-result { margin-top: 12px; }
.import-result ul { margin: 6px 0 0; padding-left: 20px; color: var(--danger); font-size: 13.5px; }
.notice { border-radius: var(--radius-sm); padding: 10px 12px; font-size: 14px; }
.notice.error { background: var(--danger-soft); color: var(--danger); }
.notice.ok { background: var(--ok-soft); color: var(--ok); }
.count-list { margin: 8px 0; padding-left: 20px; }

.toast {
  position: fixed; left: 50%; bottom: 20px; transform: translateX(-50%) translateY(20px);
  background: #17212b; color: #fff; padding: 10px 16px; border-radius: 10px; font-size: 14px;
  opacity: 0; pointer-events: none; transition: opacity .2s, transform .2s; max-width: calc(100vw - 32px); z-index: 50;
}
.toast.show { opacity: 1; transform: translateX(-50%) translateY(0); }

/* ---------- Tablet & phone ---------- */
@media (max-width: 900px) {
  .shell { flex-direction: column; min-height: 0; }
  .sidebar {
    width: auto; flex: none; height: auto; position: sticky; top: 0; z-index: 20;
    flex-direction: row; flex-wrap: wrap; align-items: center; gap: 8px 12px; padding: 10px 16px;
    border-right: 0; border-bottom: 1px solid var(--border);
  }
  .brand { padding: 0; }
  .sidebar-foot { margin: 0 0 0 auto; }
  .sidebar-foot .btn { width: auto; min-height: 36px; padding: 6px 12px; font-size: 13px; }
  .storage-note { display: none; }
  .nav {
    order: 3; flex-direction: row; width: 100%; overflow-x: auto; gap: 4px;
    scrollbar-width: none; margin: 0 -4px;
  }
  .nav::-webkit-scrollbar { display: none; }
  .nav a { padding: 7px 12px; font-size: 14px; }
  .main { padding: 18px 16px 40px; }
}
@media (max-width: 520px) {
  .nav { display: grid; grid-template-columns: repeat(3, 1fr); overflow: visible; margin: 0; }
  .nav a { text-align: center; padding: 7px 4px; }
}

@media (max-width: 640px) {
  .page-head h1 { font-size: 21px; }
  .page-actions { width: 100%; }
  .page-actions .btn { flex: 1; }
  .cards { grid-template-columns: 1fr 1fr; gap: 10px; }
  .card { padding: 12px 14px; }
  .card-value { font-size: 20px; }
  .form-grid { grid-template-columns: 1fr; }
  .period-bar .field { flex: 1 1 100%; }

  /* Tables become stacked cards */
  .table-wrap { background: transparent; border: 0; box-shadow: none; overflow: visible; }
  .data-table, .data-table tbody, .data-table tr, .data-table td { display: block; width: 100%; }
  .data-table thead { display: none; }
  .data-table tr {
    background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius);
    box-shadow: var(--shadow); margin-bottom: 10px; padding: 6px 0;
  }
  .data-table tbody tr:hover td { background: transparent; }
  .data-table td {
    border: 0; padding: 6px 14px; display: flex; justify-content: space-between; align-items: center;
    gap: 12px; text-align: right;
  }
  .data-table td::before {
    content: attr(data-label); font-size: 12px; font-weight: 600; color: var(--text-3);
    text-align: left; flex: 0 0 auto; text-transform: uppercase; letter-spacing: .03em;
  }
  .data-table td.cell-title { display: block; text-align: left; padding-top: 8px; }
  .data-table td.cell-title::before { display: none; }
  .data-table td > * { min-width: 0; }
  .data-table .cell-wrap { max-width: none; text-align: right; }
  .data-table td.actions { justify-content: flex-end; border-top: 1px solid var(--border); margin-top: 4px; padding-top: 10px; }
  .data-table td.actions::before { display: none; }
  /* The 2-column pipeline table fits a phone, so keep it a real table. */
  .pipeline-wrap { background: var(--surface); border: 1px solid var(--border); box-shadow: var(--shadow); overflow: hidden; }
  .pipeline-table { display: table; }
  .pipeline-table tbody { display: table-row-group; }
  .pipeline-table tr { display: table-row; border: 0; box-shadow: none; border-radius: 0; margin: 0; padding: 0; background: none; }
  .pipeline-table td { display: table-cell; width: auto; border-bottom: 1px solid var(--border); padding: 8px 14px; text-align: left; }
  .pipeline-table td.num { text-align: right; }
  .pipeline-table td::before { display: none; }

  .dialog { width: 100vw; max-width: 100vw; max-height: 100dvh; height: 100dvh; border-radius: 0; margin: 0; }
  .dialog form { max-height: 100dvh; height: 100%; }
  .dialog-body { flex: 1; }
  .dialog-small { height: auto; max-height: 90dvh; border-radius: 16px; width: calc(100vw - 24px); margin: auto; }
  .dialog-foot .btn { flex: 1; }
  .form-error { flex-basis: 100%; }
}

.sr-only { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }

/* ---------- Recovery ---------- */
.recovery {
  background: #fff8f6; border: 1px solid #f0c4bf; border-left: 5px solid var(--danger);
  border-radius: var(--radius); padding: 18px 20px; overflow-wrap: anywhere;
}
.recovery h2 { font-size: 18px; color: var(--danger); margin-bottom: 8px; }
.recovery p { margin: 0 0 10px; }
.recovery details { margin: 0 0 12px; background: #fff; border: 1px solid var(--border); border-radius: var(--radius-sm); padding: 8px 12px; }
.recovery summary { cursor: pointer; font-weight: 600; }
.recovery details ul { margin: 8px 0 0; padding-left: 20px; font-size: 13.5px; color: var(--text-2); }
.recovery-size { font-size: 13px; color: var(--text-2); }
.recovery-steps { margin: 0 0 10px; padding-left: 20px; }
.recovery-actions { display: flex; flex-wrap: wrap; gap: 10px; margin: 14px 0 6px; }
.btn-danger-ghost { background: var(--surface); border-color: #e5b3ae; color: var(--danger); }
.btn-danger-ghost:hover { background: var(--danger-soft); }
.recovery .notice { margin-top: 10px; }
.preserved-list { list-style: none; margin: 0; padding: 0; }
.preserved-list li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); font-size: 14px; flex-wrap: wrap; }
@media (max-width: 640px) {
  .recovery { padding: 14px 14px; }
  .recovery-actions .btn { flex: 1 1 100%; }
}

/* ---------- Sign-in ---------- */
body.booting .shell, body.auth-required .shell { display: none; }
.auth { min-height: calc(100vh - 40px); display: flex; align-items: flex-start; justify-content: center; padding: 48px 16px; }
.auth-card {
  width: 100%; max-width: 420px; background: var(--surface); border: 1px solid var(--border);
  border-radius: 18px; box-shadow: var(--shadow); padding: 28px 26px 22px;
}
.auth-card .brand { padding: 0; margin-bottom: 18px; }
.auth-card h1 { font-size: 22px; margin-bottom: 4px; }
.auth-sub { color: var(--text-2); margin: 0 0 18px; font-size: 14px; }
.auth-card .field input { width: 100%; border: 1px solid #cdd5dc; border-radius: var(--radius-sm); padding: 9px 11px; font-size: 16px; min-height: 44px; background: #fff; }
.auth-card .btn-block + .btn-block { margin-top: 8px; }
.auth-card .btn { min-height: 44px; }
.auth-message { min-height: 0; margin: 0 0 10px; font-size: 14px; }
.auth-message.error { color: var(--danger); background: var(--danger-soft); padding: 9px 11px; border-radius: var(--radius-sm); }
.auth-message.info { color: var(--ok); background: var(--ok-soft); padding: 9px 11px; border-radius: var(--radius-sm); }
.auth-status { margin: 0 0 10px; font-size: 13.5px; color: var(--text-2); }
.auth-status:empty { display: none; }
.auth-foot { margin: 16px 0 0; font-size: 12.5px; color: var(--text-3); }
.account { display: flex; align-items: center; justify-content: space-between; gap: 8px; margin-bottom: 10px; padding: 8px 10px; background: var(--surface-2); border: 1px solid var(--border); border-radius: var(--radius-sm); }
.account-email { font-size: 12.5px; color: var(--text-2); overflow-wrap: anywhere; min-width: 0; }
.loading { color: var(--text-3); }

/* ---------- Conflicts ---------- */
.conflict-lead { margin: 0 0 8px; font-weight: 600; }
.conflict-meta { margin: 0 0 14px; font-size: 13px; color: var(--text-2); overflow-wrap: anywhere; }
.conflict-note { margin: 14px 0 0; font-size: 13.5px; color: var(--text-2); }
.conflict-table td.newer { background: var(--info-soft); }
.conflict-table td.mine { background: var(--warn-soft); }
.conflict-table td { overflow-wrap: anywhere; }
.import-note { margin: 12px 0 6px; font-size: 14px; }
.import-conflicts { list-style: none; margin: 0; padding: 0; }
.import-conflicts li { display: flex; justify-content: space-between; align-items: center; gap: 10px; padding: 8px 0; border-top: 1px solid var(--border); flex-wrap: wrap; }

@media (max-width: 900px) {
  .account { margin: 0; padding: 4px 8px; }
  .account-email { max-width: 140px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
  .sidebar-foot { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; justify-content: flex-end; }
}
@media (max-width: 640px) {
  .auth { padding: 24px 16px; }
  .auth-card { padding: 22px 18px 18px; }
  .conflict-table td.newer, .conflict-table td.mine { background: transparent; }
  .conflict-table td.newer::before { color: var(--info); }
  .conflict-table td.mine::before { color: var(--warn); }
  #conflict-dialog { height: auto; max-height: 100dvh; }
}
.account { flex-wrap: wrap; }
.account .btn { white-space: nowrap; flex: 0 0 auto; }
@media (min-width: 901px) {
  .account { flex-direction: column; align-items: stretch; }
  .account .btn { width: 100%; }
}
@media (max-width: 640px) {
  #conflict-dialog .dialog-foot { flex-direction: column-reverse; align-items: stretch; }
  #conflict-dialog .dialog-foot .btn { flex: none; width: 100%; }
}
