/* Docflow — visuals ported from the Claude Design "flowdoc" handoff,
 * variation A (action rail + tables). Graphite neutral palette.
 */
@import url('https://fonts.googleapis.com/css2?family=Inter:wght@400;500;600;700&family=JetBrains+Mono:wght@400;500;600&display=swap');

:root {
  /* Neutral palette */
  --bg: #ffffff;
  --bg-subtle: #fafafa;
  --bg-muted: #f4f4f5;
  --bg-hover: #ededef;
  --border: #e6e6e8;
  --border-strong: #d4d4d8;
  --ink: #18181b;
  --ink-2: #3f3f46;
  --ink-3: #71717a;
  --ink-4: #a1a1aa;

  --error-bg: #fdecea;
  --error-fg: #7a1f1a;
  --ok-bg: #e8f5ee;
  --ok-fg: #14532d;

  --radius: 8px;
  --radius-sm: 6px;
  --radius-lg: 12px;

  --shadow-xs: 0 1px 1px rgba(24,24,27,0.04);
  --shadow-sm: 0 1px 2px rgba(24,24,27,0.06), 0 1px 3px rgba(24,24,27,0.04);
  --shadow-md: 0 4px 12px rgba(24,24,27,0.08), 0 2px 4px rgba(24,24,27,0.04);
  --shadow-lg: 0 12px 32px rgba(24,24,27,0.12), 0 4px 12px rgba(24,24,27,0.06);

  --font-ui:   'Inter', -apple-system, BlinkMacSystemFont, system-ui, sans-serif;
  --font-mono: 'JetBrains Mono', ui-monospace, 'SF Mono', Menlo, monospace;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg-subtle);
}

body {
  font-family: var(--font-ui);
  color: var(--ink);
  font-size: 14px;
  line-height: 1.5;
  letter-spacing: -0.005em;
  -webkit-font-smoothing: antialiased;
}

button {
  font-family: inherit;
  cursor: pointer;
  border: none;
  background: none;
  color: inherit;
  padding: 0;
}

input, select, textarea {
  font-family: inherit;
  font-size: inherit;
  color: inherit;
}

a {
  color: inherit;
  text-decoration: none;
}

/* ── Top bar ─────────────────────────────────────────────────── */

.topbar {
  height: 56px;
  padding: 0 24px;
  border-bottom: 1px solid var(--border);
  background: #fff;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-left {
  display: flex;
  align-items: center;
  gap: 32px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  font-weight: 600;
  font-size: 14px;
  letter-spacing: -0.01em;
  color: var(--ink);
}

.brand:hover {
  color: var(--ink);
}

.brand-mark {
  width: 26px;
  height: 26px;
  border-radius: 6px;
  background: var(--ink);
  color: #fff;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: -0.02em;
  display: flex;
  align-items: center;
  justify-content: center;
}

.badge-pill {
  display: inline-flex;
  align-items: center;
  height: 18px;
  padding: 0 6px;
  font-family: var(--font-mono);
  font-size: 10px;
  font-weight: 500;
  letter-spacing: 0.02em;
  background: var(--bg-muted);
  color: var(--ink-2);
  border: 1px solid var(--border);
  border-radius: 4px;
}

.topnav {
  display: flex;
  gap: 4px;
  font-size: 13px;
}

.topnav a {
  padding: 6px 10px;
  border-radius: 5px;
  color: var(--ink-3);
  font-weight: 400;
}

.topnav a:hover {
  background: var(--bg-muted);
  color: var(--ink);
}

.topnav a.active {
  color: var(--ink);
  font-weight: 500;
  background: var(--bg-muted);
}

.topbar-right {
  display: flex;
  align-items: center;
  gap: 12px;
}

.user-avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--bg-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-2);
}

.user-email {
  font-size: 12px;
  color: var(--ink-3);
}

.logout-btn {
  color: var(--ink-3);
  font-size: 12px;
  padding: 4px 8px;
  border-radius: 4px;
}

.logout-btn:hover {
  color: var(--ink);
  background: var(--bg-muted);
}

/* ── Layout ──────────────────────────────────────────────────── */

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

.page-main {
  flex: 1;
  display: grid;
  grid-template-columns: 320px 1fr;
  min-height: 0;
}

.page-main.single {
  display: block;
  max-width: 960px;
  margin: 0 auto;
  padding: 32px 28px 48px;
  width: 100%;
}

.page-main.narrow {
  max-width: 520px;
}

/* Left rail */
.rail {
  padding: 24px 20px;
  border-right: 1px solid var(--border);
  background: #fff;
  overflow: auto;
}

.rail-section {
  margin-bottom: 18px;
}

.rail-heading {
  font-size: 10.5px;
  font-weight: 600;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 10px;
}

.rail hr {
  height: 1px;
  background: var(--border);
  border: none;
  margin: 20px -20px;
}

/* Main content area (next to rail) */
.content {
  display: flex;
  flex-direction: column;
  min-width: 0;
  min-height: 0;
  padding: 22px 28px 28px;
  overflow: auto;
}

/* ── Action tiles ────────────────────────────────────────────── */

.tiles-col {
  display: grid;
  gap: 8px;
}

.tile-action {
  display: flex;
  align-items: flex-start;
  gap: 12px;
  padding: 14px;
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow-xs);
  text-align: left;
  transition: transform 0.14s ease, box-shadow 0.14s ease;
  color: var(--ink);
  width: 100%;
}

.tile-action:hover {
  transform: translateY(-1px);
  box-shadow: var(--shadow-md);
}

.tile-action.primary {
  background: var(--ink);
  color: #fff;
  border-color: var(--ink);
  box-shadow: var(--shadow-sm);
}

.tile-action.primary:hover {
  background: #000;
}

.tile-icon {
  width: 34px;
  height: 34px;
  border-radius: 7px;
  background: var(--bg-muted);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  color: var(--ink);
}

.tile-action.primary .tile-icon {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
}

.tile-body {
  flex: 1;
  min-width: 0;
}

.tile-title {
  font-size: 13.5px;
  font-weight: 600;
  letter-spacing: -0.005em;
  margin-bottom: 2px;
}

.tile-sub {
  font-size: 11.5px;
  line-height: 1.4;
  color: var(--ink-3);
}

.tile-action.primary .tile-sub {
  color: rgba(255, 255, 255, 0.7);
}

.tile-chev {
  color: var(--ink-4);
  margin-top: 10px;
  flex-shrink: 0;
}

.tile-action.primary .tile-chev {
  color: rgba(255, 255, 255, 0.5);
}

/* Compact facsimile tile in the rail */
.rail-row {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-xs);
  color: var(--ink);
  width: 100%;
}

.rail-row:hover {
  background: var(--bg-subtle);
  border-color: var(--ink-4);
}

.rail-status {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 10px;
  padding: 8px 10px;
  background: var(--bg-subtle);
  border-radius: 6px;
  font-size: 11.5px;
  color: var(--ink-3);
}

.rail-status .dot {
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: var(--ink);
}

.rail-status strong {
  color: var(--ink);
  font-weight: 500;
}

/* Stats grid */
.stats-grid {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 8px;
}

.stat {
  padding: 10px 12px;
  background: var(--bg-subtle);
  border-radius: 7px;
}

.stat-k {
  font-size: 10.5px;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 2px;
}

.stat-v {
  font-size: 16px;
  font-weight: 600;
  font-family: var(--font-mono);
  letter-spacing: -0.02em;
}

/* ── Content header ──────────────────────────────────────────── */

.content-head {
  display: flex;
  align-items: flex-end;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 14px;
  flex-shrink: 0;
}

.content-head h1 {
  margin: 0;
  font-size: 20px;
  font-weight: 600;
  letter-spacing: -0.015em;
}

.content-head .sub {
  margin: 2px 0 0;
  font-size: 13px;
  color: var(--ink-3);
}

.content-head-actions {
  display: flex;
  gap: 8px;
}

/* ── Table ───────────────────────────────────────────────────── */

.card {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
}

table.doc-table {
  width: 100%;
  border-collapse: separate;
  border-spacing: 0;
  font-size: 13px;
}

table.doc-table thead th {
  text-align: left;
  font-weight: 500;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--ink-3);
  padding: 10px 12px;
  background: var(--bg-subtle);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 1;
}

table.doc-table thead th:first-child { padding-left: 20px; }
table.doc-table thead th:last-child  { padding-right: 20px; text-align: right; }

table.doc-table tbody td {
  padding: 12px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}

table.doc-table tbody td:first-child { padding-left: 20px; }
table.doc-table tbody td:last-child  { padding-right: 20px; text-align: right; }
table.doc-table tbody tr { transition: background 0.1s; }
table.doc-table tbody tr:hover { background: var(--bg-subtle); }
table.doc-table tbody tr:last-child td { border-bottom: none; }

.empty-row {
  padding: 48px 20px;
  text-align: center;
  color: var(--ink-3);
}

/* ── Status badges ───────────────────────────────────────────── */

.status {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  height: 22px;
  padding: 0 8px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
  letter-spacing: 0.01em;
  background: var(--bg-muted);
  color: var(--ink-2);
  border: 1px solid var(--border);
}

.status::before {
  content: '';
  width: 6px;
  height: 6px;
  border-radius: 50%;
  background: currentColor;
  opacity: 0.6;
}

.status-draft  { background: #fff; color: var(--ink-3); }
.status-signed { background: var(--ink); color: #fff; border-color: var(--ink); }
.status-paid   { background: var(--bg-muted); color: var(--ink); border-color: var(--border-strong); }

/* ── Mono/tnum ──────────────────────────────────────────────── */
.mono { font-family: var(--font-mono); font-feature-settings: 'tnum'; }
.tnum { font-variant-numeric: tabular-nums; font-feature-settings: 'tnum'; }

/* ── Buttons ─────────────────────────────────────────────────── */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  height: 36px;
  padding: 0 14px;
  border-radius: var(--radius-sm);
  font-size: 13px;
  font-weight: 500;
  letter-spacing: -0.005em;
  white-space: nowrap;
  transition: all 0.12s ease;
  border: 1px solid transparent;
}

.btn-primary {
  background: var(--ink);
  color: #fff;
  box-shadow: var(--shadow-xs), inset 0 1px 0 rgba(255,255,255,0.08);
}
.btn-primary:hover { background: #000; transform: translateY(-0.5px); box-shadow: var(--shadow-sm), inset 0 1px 0 rgba(255,255,255,0.08); }
.btn-primary:active { transform: translateY(0); }
.btn-primary:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

.btn-secondary {
  background: #fff;
  color: var(--ink);
  border-color: var(--border-strong);
  box-shadow: var(--shadow-xs);
}
.btn-secondary:hover { background: var(--bg-subtle); border-color: var(--ink-4); }

.btn-ghost {
  background: transparent;
  color: var(--ink-2);
}
.btn-ghost:hover { background: var(--bg-muted); color: var(--ink); }

.btn-sm { height: 28px; padding: 0 10px; font-size: 12px; border-radius: 5px; gap: 6px; }
.btn-xs { height: 24px; padding: 0 8px; font-size: 11.5px; border-radius: 4px; gap: 4px; }

.icon-btn {
  width: 28px;
  height: 28px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  border-radius: 5px;
  color: var(--ink-3);
  transition: all 0.12s;
}

.icon-btn:hover { background: var(--bg-muted); color: var(--ink); }

.row-actions {
  display: inline-flex;
  gap: 6px;
  justify-content: flex-end;
}

/* ── Inputs ──────────────────────────────────────────────────── */

.fld {
  display: block;
  margin-bottom: 14px;
}

.fld-label, label {
  display: block;
  font-size: 11.5px;
  font-weight: 500;
  color: var(--ink-3);
  margin-bottom: 6px;
  letter-spacing: 0.01em;
}

label small {
  color: var(--ink-4);
  font-weight: 400;
}

input[type="text"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="number"],
input[type="file"],
input[type="search"],
select,
textarea {
  width: 100%;
  height: 36px;
  padding: 0 12px;
  border-radius: var(--radius-sm);
  border: 1px solid var(--border-strong);
  background: #fff;
  transition: all 0.12s ease;
  font-size: 13px;
  color: var(--ink);
}

textarea {
  height: auto;
  padding: 10px 12px;
  resize: vertical;
  min-height: 72px;
  line-height: 1.5;
}

input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--ink);
  box-shadow: 0 0 0 3px rgba(24,24,27,0.08);
}

input::placeholder, textarea::placeholder {
  color: var(--ink-4);
}

input[type="checkbox"],
input[type="radio"] {
  width: auto;
  height: auto;
  margin: 0 6px 0 0;
  vertical-align: middle;
}

/* Search input with leading icon */
.input-search {
  position: relative;
}

.input-search input {
  padding-left: 30px;
}

.input-search .icon {
  position: absolute;
  left: 10px;
  top: 50%;
  transform: translateY(-50%);
  color: var(--ink-4);
  pointer-events: none;
}

.input-search .kbd {
  position: absolute;
  right: 8px;
  top: 50%;
  transform: translateY(-50%);
}

.kbd {
  font-family: var(--font-mono);
  font-size: 10.5px;
  padding: 1px 5px;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-bottom-width: 2px;
  border-radius: 4px;
  color: var(--ink-3);
  line-height: 1;
  display: inline-block;
}

/* ── Filter pill group ──────────────────────────────────────── */

.pillgroup {
  display: flex;
  background: #fff;
  border: 1px solid var(--border-strong);
  border-radius: 6px;
  padding: 2px;
  box-shadow: var(--shadow-xs);
}

.pillgroup button {
  padding: 0 10px;
  height: 30px;
  font-size: 12px;
  font-weight: 500;
  border-radius: 4px;
  background: transparent;
  color: var(--ink-2);
  transition: all 0.12s;
}

.pillgroup button.on,
.pillgroup a.on {
  background: var(--ink);
  color: #fff;
}

.pillgroup a {
  padding: 0 10px;
  height: 30px;
  display: inline-flex;
  align-items: center;
  font-size: 12px;
  font-weight: 500;
  border-radius: 4px;
  color: var(--ink-2);
}

/* ── Form pages (login, contract, invoice, act, facsimile) ─── */

.form-page {
  background: #fff;
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-xs);
  overflow: hidden;
}

.form-page-head {
  padding: 20px 24px 16px;
  border-bottom: 1px solid var(--border);
}

.form-page-head .step {
  font-size: 11px;
  font-weight: 500;
  color: var(--ink-3);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-bottom: 4px;
}

.form-page-head h1 {
  margin: 0;
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
}

.form-page-head .subtitle {
  margin: 4px 0 0;
  font-size: 13px;
  color: var(--ink-3);
}

.form-page-body {
  padding: 20px 24px;
}

fieldset {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 14px 18px 16px;
  margin: 0 0 14px;
  background: #fff;
}

fieldset legend {
  font-size: 11.5px;
  font-weight: 600;
  color: var(--ink-2);
  text-transform: uppercase;
  letter-spacing: 0.04em;
  padding: 0 6px;
}

.form-page-foot {
  padding: 14px 20px;
  border-top: 1px solid var(--border);
  background: var(--bg-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.foot-hint {
  font-size: 12px;
  color: var(--ink-3);
  display: flex;
  align-items: center;
  gap: 8px;
}

/* Grid rows */
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.row-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.row-4 { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }

/* Multi-object list */
.object-row {
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  padding: 12px 14px 4px;
  margin-bottom: 10px;
  background: var(--bg-subtle);
}

.obj-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 8px;
  font-size: 12px;
  color: var(--ink-3);
}

.ap-row {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 8px;
  margin-bottom: 6px;
  align-items: start;
}

.ap-row textarea {
  min-height: 40px;
}

/* Lookup status inline next to field labels */
.lookup-status {
  margin-left: 8px;
  font-weight: 400;
  font-size: 11px;
  color: var(--ink-4);
}
.lookup-status.ok  { color: var(--ok-fg); }
.lookup-status.err { color: var(--error-fg); }

/* Alerts */
.alert {
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  margin-bottom: 12px;
  font-size: 13px;
}
.alert.error { background: var(--error-bg); color: var(--error-fg); }
.alert.ok    { background: var(--ok-bg);    color: var(--ok-fg); }

/* Login */
.login-box {
  max-width: 380px;
  margin: 80px auto 0;
}

/* Facsimile preview */
.facs-preview img {
  max-width: 260px;
  max-height: 120px;
  border: 1px dashed var(--border-strong);
  padding: 8px;
  background: #fff;
  border-radius: var(--radius-sm);
}

/* Tables list on home when empty */
.tiles-home {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(240px, 1fr));
  gap: 12px;
  margin-top: 10px;
}

/* Scrollbars in Webkit */
.scroll::-webkit-scrollbar { width: 10px; height: 10px; }
.scroll::-webkit-scrollbar-track { background: transparent; }
.scroll::-webkit-scrollbar-thumb { background: #e4e4e7; border-radius: 5px; border: 2px solid #fff; }
.scroll::-webkit-scrollbar-thumb:hover { background: #d4d4d8; }

/* Utilities */
.hidden { display: none !important; }
.mr-auto { margin-right: auto; }
.nowrap { white-space: nowrap; }

/* ── Status legend (under table header) ───────────────────── */

.status-legend {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 8px;
  padding: 8px 14px;
  margin-bottom: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--bg-subtle);
  font-size: 12px;
  color: var(--ink-3);
}

.status-legend .status { margin: 0 2px; }

/* ── Modal overlay ────────────────────────────────────────── */

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(24, 24, 27, 0.32);
  backdrop-filter: blur(4px);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  z-index: 200;
  animation: modal-fade 0.18s ease;
}

.modal {
  width: 100%;
  max-width: 420px;
  background: #fff;
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  border: 1px solid var(--border);
  padding: 28px 24px 20px;
  text-align: center;
  animation: modal-rise 0.22s cubic-bezier(.2,.8,.3,1);
}

.modal-icon {
  width: 56px;
  height: 56px;
  margin: 0 auto 14px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg-muted);
}

.modal-icon.ok  { background: var(--ink); color: #fff; }
.modal-icon.err { background: var(--error-bg); color: var(--error-fg); }

.modal-title {
  font-size: 18px;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin-bottom: 8px;
}

.modal-msg {
  font-size: 13px;
  color: var(--ink-3);
  line-height: 1.5;
  margin-bottom: 18px;
}

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

@keyframes modal-fade { from { opacity: 0; } }
@keyframes modal-rise { from { opacity: 0; transform: translateY(8px) scale(0.98); } }

/* Inline spinner inside submit buttons */
.spinner {
  width: 12px;
  height: 12px;
  border: 1.5px solid rgba(255, 255, 255, 0.3);
  border-top-color: #fff;
  border-radius: 50%;
  display: inline-block;
  animation: spin 0.7s linear infinite;
  vertical-align: middle;
  margin-right: 6px;
}

@keyframes spin { to { transform: rotate(360deg); } }

@media (max-width: 960px) {
  .page-main { grid-template-columns: 1fr; }
  .rail { border-right: 0; border-bottom: 1px solid var(--border); }
  .row-2, .row-3, .row-4 { grid-template-columns: 1fr; }
  .topnav { display: none; }
}
