/* DrawBook — construction progress billing */
:root {
  --ink: #142033;
  --ink-soft: #3d4a5c;
  --muted: #6b7789;
  --line: #d8dee8;
  --line-strong: #b8c2d1;
  --bg: #f3f1eb;
  --surface: #ffffff;
  --surface-2: #f7f6f2;
  --accent: #c45c26;
  --accent-hover: #a34a1c;
  --accent-soft: #fdf0e8;
  --navy: #1a2b44;
  --navy-hover: #243a5a;
  --ok: #1f6b4a;
  --ok-bg: #e6f4ed;
  --warn: #8a5a00;
  --warn-bg: #fff6e0;
  --danger: #9b1c1c;
  --danger-bg: #fdecec;
  --shadow: 0 1px 2px rgba(20, 32, 51, 0.06), 0 8px 24px rgba(20, 32, 51, 0.06);
  --radius: 10px;
  --font: "Segoe UI", system-ui, -apple-system, "Helvetica Neue", Arial, sans-serif;
  --mono: "ui-monospace", "SF Mono", Menlo, Consolas, monospace;
  --sidebar-w: 260px;
}

*,
*::before,
*::after {
  box-sizing: border-box;
}

html,
body {
  margin: 0;
  padding: 0;
  min-height: 100%;
  font-family: var(--font);
  color: var(--ink);
  background: var(--bg);
  font-size: 15px;
  line-height: 1.45;
}

body {
  display: flex;
  flex-direction: column;
  min-height: 100vh;
}

button,
input,
select,
textarea {
  font: inherit;
  color: inherit;
}

button {
  cursor: pointer;
}

a {
  color: var(--accent);
}

/* —— Shell —— */
.app-header {
  display: flex;
  align-items: center;
  gap: 16px;
  padding: 10px 18px;
  background: var(--navy);
  color: #f5f3ee;
  border-bottom: 3px solid var(--accent);
  position: sticky;
  top: 0;
  z-index: 40;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  min-width: 160px;
}

.brand-mark {
  width: 34px;
  height: 34px;
  border-radius: 8px;
  background: linear-gradient(145deg, var(--accent), #e08a4f);
  display: grid;
  place-items: center;
  font-weight: 800;
  font-size: 13px;
  letter-spacing: -0.03em;
  color: #fff;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, 0.2);
}

.brand-text {
  display: flex;
  flex-direction: column;
  line-height: 1.1;
}

.brand-text strong {
  font-size: 16px;
  letter-spacing: 0.01em;
}

.brand-text span {
  font-size: 11px;
  opacity: 0.72;
  font-weight: 400;
}

.header-actions {
  margin-left: auto;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

.privacy-pill {
  font-size: 12px;
  background: rgba(255, 255, 255, 0.1);
  border: 1px solid rgba(255, 255, 255, 0.18);
  padding: 4px 10px;
  border-radius: 999px;
  color: #e8e4dc;
}

.app-body {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  flex: 1;
  min-height: 0;
}

/* —— Sidebar —— */
.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--line);
  padding: 14px 12px 24px;
  overflow-y: auto;
}

.sidebar h2 {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 12px 8px 8px;
  font-weight: 650;
}

.project-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.project-list li button {
  width: 100%;
  text-align: left;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 8px;
  padding: 9px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
}

.project-list li button:hover {
  background: var(--surface-2);
  border-color: var(--line);
}

.project-list li button.active {
  background: var(--accent-soft);
  border-color: #efc4a8;
}

.project-list .pname {
  font-weight: 600;
  font-size: 13.5px;
  color: var(--ink);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.project-list .pmeta {
  font-size: 11.5px;
  color: var(--muted);
}

.sidebar-actions {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-top: 10px;
  padding: 0 4px;
}

/* —— Main —— */
.main {
  padding: 18px 22px 48px;
  overflow-y: auto;
  min-width: 0;
}

.empty-state {
  max-width: 640px;
  margin: 48px auto;
  background: var(--surface);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 36px 40px;
  border: 1px solid var(--line);
}

.empty-state h1 {
  margin: 0 0 10px;
  font-size: 26px;
  letter-spacing: -0.02em;
}

.empty-state p {
  color: var(--ink-soft);
  margin: 0 0 18px;
}

.empty-state ul {
  margin: 0 0 22px;
  padding-left: 1.2em;
  color: var(--ink-soft);
}

.empty-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
}

/* —— Project shell —— */
.project-head {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  gap: 12px 18px;
  margin-bottom: 16px;
}

.project-head h1 {
  margin: 0;
  font-size: 24px;
  letter-spacing: -0.02em;
  flex: 1;
  min-width: 200px;
}

.project-head .title-edit {
  font-size: 24px;
  font-weight: 700;
  border: 1px solid transparent;
  background: transparent;
  border-radius: 6px;
  padding: 2px 6px;
  margin: -2px -6px;
  width: 100%;
  max-width: 520px;
}

.project-head .title-edit:hover,
.project-head .title-edit:focus {
  border-color: var(--line-strong);
  background: var(--surface);
  outline: none;
}

.stat-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 10px;
  margin-bottom: 18px;
}

.stat-card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
  box-shadow: var(--shadow);
}

.stat-card label {
  display: block;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 4px;
  font-weight: 600;
}

.stat-card .value {
  font-size: 18px;
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  letter-spacing: -0.01em;
}

.stat-card.highlight {
  background: var(--navy);
  border-color: var(--navy);
  color: #fff;
}

.stat-card.highlight label {
  color: rgba(255, 255, 255, 0.7);
}

/* —— Tabs —— */
.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
  border-bottom: 1px solid var(--line);
  margin-bottom: 16px;
  padding-bottom: 0;
}

.tabs button {
  border: none;
  background: transparent;
  padding: 10px 14px;
  color: var(--ink-soft);
  font-weight: 600;
  font-size: 13.5px;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  border-radius: 6px 6px 0 0;
}

.tabs button:hover {
  color: var(--ink);
  background: rgba(0, 0, 0, 0.03);
}

.tabs button.active {
  color: var(--accent);
  border-bottom-color: var(--accent);
}

.panel {
  display: none;
}

.panel.active {
  display: block;
}

.card {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 16px 18px;
  margin-bottom: 14px;
}

.card h3 {
  margin: 0 0 12px;
  font-size: 15px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

.card .hint {
  font-size: 13px;
  color: var(--muted);
  margin: -6px 0 12px;
}

/* —— Forms —— */
.form-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 12px 14px;
}

.field {
  display: flex;
  flex-direction: column;
  gap: 4px;
}

.field label {
  font-size: 12px;
  font-weight: 650;
  color: var(--ink-soft);
}

.field input,
.field select,
.field textarea {
  border: 1px solid var(--line-strong);
  border-radius: 7px;
  padding: 8px 10px;
  background: #fff;
  min-height: 38px;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  outline: 2px solid rgba(196, 92, 38, 0.35);
  border-color: var(--accent);
}

.field textarea {
  min-height: 72px;
  resize: vertical;
}

.field.full {
  grid-column: 1 / -1;
}

/* —— Buttons —— */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  border-radius: 8px;
  padding: 8px 14px;
  border: 1px solid transparent;
  font-weight: 650;
  font-size: 13.5px;
  line-height: 1.2;
  white-space: nowrap;
  transition: background 0.12s, border-color 0.12s, color 0.12s;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
  border-color: var(--accent);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
}

.btn-navy {
  background: var(--navy);
  color: #fff;
  border-color: var(--navy);
}

.btn-navy:hover:not(:disabled) {
  background: var(--navy-hover);
}

.btn-ghost {
  background: transparent;
  border-color: var(--line-strong);
  color: var(--ink);
}

.btn-ghost:hover:not(:disabled) {
  background: var(--surface-2);
}

.btn-danger {
  background: var(--danger-bg);
  color: var(--danger);
  border-color: #f0c0c0;
}

.btn-danger:hover:not(:disabled) {
  background: #fadada;
}

.btn-sm {
  padding: 5px 10px;
  font-size: 12.5px;
  border-radius: 6px;
}

.btn-row {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  align-items: center;
}

/* —— Tables —— */
.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
}

table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
  min-width: 720px;
}

table.data th,
table.data td {
  padding: 8px 9px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

table.data th {
  background: var(--surface-2);
  font-size: 11.5px;
  text-transform: uppercase;
  letter-spacing: 0.04em;
  color: var(--ink-soft);
  font-weight: 700;
  position: sticky;
  top: 0;
  white-space: nowrap;
}

table.data tr:last-child td {
  border-bottom: none;
}

table.data tr:hover td {
  background: #fafaf7;
}

table.data tfoot td {
  font-weight: 700;
  background: var(--surface-2);
  border-top: 2px solid var(--line-strong);
}

table.data .money,
table.data .num,
table.data input.money-input {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 12.5px;
}

table.data input.cell {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  padding: 5px 6px;
  border-radius: 5px;
  min-width: 0;
}

table.data input.cell:hover {
  border-color: var(--line);
  background: #fff;
}

table.data input.cell:focus {
  outline: none;
  border-color: var(--accent);
  background: #fff;
  box-shadow: 0 0 0 2px rgba(196, 92, 38, 0.2);
}

table.data input.money-input {
  width: 110px;
}

table.data input.narrow {
  width: 56px;
  text-align: center;
}

table.data .actions {
  white-space: nowrap;
  width: 1%;
}

.pct-bar {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 90px;
}

.pct-bar .track {
  flex: 1;
  height: 6px;
  background: #e6e9ef;
  border-radius: 99px;
  overflow: hidden;
}

.pct-bar .fill {
  height: 100%;
  background: linear-gradient(90deg, #2f6f4e, #3d9b6a);
  border-radius: 99px;
}

.pct-bar.over .fill {
  background: var(--danger);
}

.pct-bar span {
  font-size: 11.5px;
  font-variant-numeric: tabular-nums;
  color: var(--muted);
  min-width: 36px;
  text-align: right;
}

/* —— Draw editor —— */
.summary-box {
  max-width: 440px;
  margin-left: auto;
}

.summary-box table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

.summary-box td {
  padding: 7px 10px;
  border: 1px solid var(--line);
}

.summary-box td:last-child {
  text-align: right;
  font-variant-numeric: tabular-nums;
  font-family: var(--mono);
  font-size: 12.5px;
  width: 120px;
}

.summary-box tr.due td {
  background: var(--navy);
  color: #fff;
  font-weight: 700;
  font-size: 15px;
}

.summary-box tr.due td:last-child {
  font-size: 15px;
}

.alert {
  border-radius: 8px;
  padding: 10px 12px;
  margin-bottom: 12px;
  font-size: 13.5px;
}

.alert ul {
  margin: 6px 0 0;
  padding-left: 1.2em;
}

.alert-error {
  background: var(--danger-bg);
  color: var(--danger);
  border: 1px solid #f0c0c0;
}

.alert-warn {
  background: var(--warn-bg);
  color: var(--warn);
  border: 1px solid #f0dca0;
}

.alert-ok {
  background: var(--ok-bg);
  color: var(--ok);
  border: 1px solid #b7dfc9;
}

.app-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.app-item {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 10px 14px;
  padding: 12px 14px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--surface-2);
}

.app-item .anum {
  font-weight: 800;
  color: var(--navy);
  min-width: 52px;
}

.app-item .adue {
  font-weight: 700;
  font-variant-numeric: tabular-nums;
  margin-left: auto;
}

/* —— Modal —— */
.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 32, 51, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
  padding: 16px;
}

.modal {
  background: var(--surface);
  border-radius: 12px;
  max-width: 480px;
  width: 100%;
  padding: 22px;
  box-shadow: 0 20px 50px rgba(0, 0, 0, 0.25);
  border: 1px solid var(--line);
}

.modal h2 {
  margin: 0 0 8px;
  font-size: 18px;
}

.modal p {
  margin: 0 0 16px;
  color: var(--ink-soft);
  font-size: 14px;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 8px;
  flex-wrap: wrap;
}

.toast {
  position: fixed;
  bottom: 20px;
  right: 20px;
  background: var(--navy);
  color: #fff;
  padding: 10px 16px;
  border-radius: 8px;
  box-shadow: var(--shadow);
  z-index: 120;
  font-size: 13.5px;
  animation: fadein 0.2s ease;
}

@keyframes fadein {
  from {
    opacity: 0;
    transform: translateY(6px);
  }
  to {
    opacity: 1;
    transform: none;
  }
}

.footer-note {
  margin-top: 28px;
  font-size: 12px;
  color: var(--muted);
  max-width: 720px;
  line-height: 1.5;
}

/* —— Responsive —— */
@media (max-width: 860px) {
  .app-body {
    grid-template-columns: 1fr;
  }

  .sidebar {
    border-right: none;
    border-bottom: 1px solid var(--line);
    max-height: 220px;
  }

  .main {
    padding: 14px 12px 40px;
  }

  .privacy-pill {
    display: none;
  }
}

@media print {
  .app-header,
  .sidebar,
  .tabs,
  .btn-row,
  .header-actions {
    display: none !important;
  }

  .app-body {
    display: block;
  }

  .main {
    padding: 0;
  }
}
