/* M65 Work — design tokens + components. Hand-written, no build step. */
:root {
  --bg: #f5f6fa;
  --surface: #ffffff;
  --surface-2: #f9fafc;
  --column: #eef0f6;
  --border: #e3e6ef;
  --border-strong: #d2d6e2;
  --text: #1a1d2e;
  --text-2: #4b5168;
  --muted: #8389a0;
  --accent: #5b54e8;
  --accent-hover: #4a43d4;
  --accent-soft: #eeedfd;
  --accent-ring: rgba(91, 84, 232, .22);
  --pending: #d98a1c;
  --pending-soft: #fdf3e3;
  --progress: #2f7fe0;
  --progress-soft: #e7f1fd;
  --done: #17a06b;
  --done-soft: #e3f6ee;
  --danger: #d9434b;
  --danger-soft: #fdecec;
  --radius: 14px;
  --radius-sm: 9px;
  --shadow-sm: 0 1px 2px rgba(22, 27, 45, .05), 0 1px 1px rgba(22, 27, 45, .03);
  --shadow: 0 1px 2px rgba(22, 27, 45, .04), 0 4px 14px rgba(22, 27, 45, .06);
  --shadow-lg: 0 20px 50px rgba(22, 27, 45, .18), 0 4px 12px rgba(22, 27, 45, .08);
  --font: "Inter", ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  color-scheme: light;
}

*, *::before, *::after { box-sizing: border-box; }
html { -webkit-text-size-adjust: 100%; }
body {
  margin: 0; background: var(--bg); color: var(--text);
  font: 14.5px/1.5 var(--font); font-feature-settings: "cv11", "ss01";
  -webkit-font-smoothing: antialiased;
}
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }
h1, h2, h3 { margin: 0; letter-spacing: -.015em; line-height: 1.25; }
[x-cloak] { display: none !important; }
.sr-only { position: absolute; width: 1px; height: 1px; overflow: hidden; clip: rect(0 0 0 0); white-space: nowrap; }
.muted { color: var(--muted); }
.num { font-variant-numeric: tabular-nums; }

/* ---------- App shell ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  background: rgba(255, 255, 255, .86); backdrop-filter: saturate(1.6) blur(12px);
  border-bottom: 1px solid var(--border);
}
.topbar-inner {
  max-width: 1440px; margin: 0 auto; height: 60px; padding: 0 24px;
  display: flex; align-items: center; gap: 28px;
}
.brand { display: flex; align-items: center; gap: 10px; font-weight: 700; color: var(--text); font-size: 15.5px; letter-spacing: -.01em; }
.brand:hover { color: var(--text); }
.brand-mark {
  width: 30px; height: 30px; border-radius: 9px; display: grid; place-items: center;
  background: linear-gradient(135deg, #6d66f2, #4a43d4); color: #fff; font-size: 13px; font-weight: 800;
  box-shadow: 0 2px 8px rgba(91, 84, 232, .35);
}
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; scrollbar-width: none; }
.nav::-webkit-scrollbar { display: none; }
.nav a {
  padding: 7px 12px; border-radius: 8px; color: var(--text-2); font-weight: 500; white-space: nowrap;
  transition: background .15s, color .15s;
}
.nav a:hover { background: var(--column); color: var(--text); }
.nav a.active { background: var(--accent-soft); color: var(--accent); }
.usermenu { position: relative; }
.usermenu > button {
  display: flex; align-items: center; gap: 10px; background: none; border: 0; padding: 4px 6px 4px 4px;
  border-radius: 999px; cursor: pointer; font: inherit; color: var(--text);
}
.usermenu > button:hover { background: var(--column); }
.usermenu .who { text-align: left; line-height: 1.2; }
.usermenu .who small { display: block; color: var(--muted); font-size: 11.5px; }
.dropdown {
  position: absolute; right: 0; top: calc(100% + 8px); min-width: 200px; padding: 6px;
  background: var(--surface); border: 1px solid var(--border); border-radius: 12px; box-shadow: var(--shadow-lg);
}
.dropdown a, .dropdown button {
  display: block; width: 100%; text-align: left; padding: 8px 10px; border-radius: 8px;
  color: var(--text-2); background: none; border: 0; font: inherit; cursor: pointer;
}
.dropdown a:hover, .dropdown button:hover { background: var(--column); color: var(--text); }

.avatar {
  width: 28px; height: 28px; border-radius: 50%; display: inline-grid; place-items: center; flex: none;
  font-size: 11px; font-weight: 700; color: #fff; background: #8a84f0;
}
.avatar.sm { width: 22px; height: 22px; font-size: 9.5px; }
.avatar.none { background: var(--column); color: var(--muted); border: 1px dashed var(--border-strong); }

.page { max-width: 1440px; margin: 0 auto; padding: 28px 24px 64px; }
.page.narrow { max-width: 880px; }
.page-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 16px; flex-wrap: wrap; margin-bottom: 22px; }
.page-head h1 { font-size: 24px; font-weight: 700; }
.page-head p { margin: 4px 0 0; color: var(--muted); }
.actions { display: flex; gap: 10px; flex-wrap: wrap; align-items: center; }

/* ---------- Buttons & forms ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  height: 38px; padding: 0 15px; border-radius: 10px; border: 1px solid var(--border-strong);
  background: var(--surface); color: var(--text); font: 600 13.5px/1 var(--font); cursor: pointer;
  box-shadow: var(--shadow-sm); transition: background .15s, border-color .15s, box-shadow .15s, transform .05s;
  white-space: nowrap;
}
.btn:hover { background: var(--surface-2); border-color: #c2c7d6; color: var(--text); }
.btn:active { transform: translateY(1px); }
.btn:focus-visible { outline: none; box-shadow: 0 0 0 4px var(--accent-ring); }
.btn svg { width: 16px; height: 16px; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; box-shadow: 0 1px 2px rgba(74, 67, 212, .3), inset 0 1px 0 rgba(255,255,255,.12); }
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); color: #fff; }
.btn-success { background: var(--done); border-color: var(--done); color: #fff; }
.btn-success:hover { background: #128a5b; border-color: #128a5b; color: #fff; }
.btn-danger { color: var(--danger); }
.btn-danger:hover { background: var(--danger-soft); border-color: #f1c2c5; color: var(--danger); }
.btn-ghost { background: transparent; border-color: transparent; box-shadow: none; color: var(--text-2); }
.btn-ghost:hover { background: var(--column); border-color: transparent; }
.btn-sm { height: 32px; padding: 0 11px; font-size: 12.5px; border-radius: 8px; }
.btn-block { width: 100%; }
.btn[disabled] { opacity: .55; cursor: not-allowed; }

.field { margin-bottom: 16px; }
.field label, .label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 6px; color: var(--text-2); }
.input, .select, .textarea {
  width: 100%; height: 40px; padding: 0 12px; border: 1px solid var(--border-strong); border-radius: 10px;
  background: var(--surface); color: var(--text); font: 14px var(--font);
  transition: border-color .15s, box-shadow .15s;
}
.textarea { height: auto; min-height: 96px; padding: 10px 12px; resize: vertical; line-height: 1.5; }
.select { appearance: none; padding-right: 34px; background: var(--surface) url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%238389a0' stroke-width='2' viewBox='0 0 24 24'%3E%3Cpath d='m6 9 6 6 6-6'/%3E%3C/svg%3E") no-repeat right 12px center; }
.input:focus, .select:focus, .textarea:focus { outline: none; border-color: var(--accent); box-shadow: 0 0 0 4px var(--accent-ring); }
.input-prefix { position: relative; }
.input-prefix span { position: absolute; left: 12px; top: 50%; transform: translateY(-50%); color: var(--muted); font-weight: 600; }
.input-prefix .input { padding-left: 30px; }
.error { color: var(--danger); font-size: 12.5px; margin-top: 5px; }
.hint { color: var(--muted); font-size: 12.5px; margin-top: 5px; }
.row { display: grid; grid-template-columns: 1fr 1fr; gap: 14px; }
.check { display: inline-flex; align-items: center; gap: 8px; color: var(--text-2); cursor: pointer; user-select: none; }
.check input { width: 16px; height: 16px; accent-color: var(--accent); }

.alert { padding: 11px 14px; border-radius: 10px; margin-bottom: 18px; font-weight: 500; border: 1px solid; }
.alert-success { background: var(--done-soft); color: #0f7a51; border-color: #bfe8d6; }
.alert-error { background: var(--danger-soft); color: #b3323a; border-color: #f4c7ca; }

.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow-sm); }
.card-pad { padding: 22px; }
.card h2 { font-size: 16px; font-weight: 650; }
.card-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; padding: 16px 22px; border-bottom: 1px solid var(--border); }

.badge {
  display: inline-flex; align-items: center; gap: 6px; height: 24px; padding: 0 10px; border-radius: 999px;
  font-size: 12px; font-weight: 600; white-space: nowrap;
}
.badge::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.badge-paid { background: var(--done-soft); color: var(--done); }
.badge-unpaid { background: var(--pending-soft); color: #b86f0c; }
.badge-plain::before { display: none; }
.badge-plain { background: var(--column); color: var(--text-2); }

/* ---------- Stats ---------- */
.stats { display: grid; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; margin-bottom: 24px; }
.stat { padding: 16px 18px; display: flex; gap: 14px; align-items: center; }
.stat-icon { width: 40px; height: 40px; border-radius: 11px; display: grid; place-items: center; flex: none; }
.stat-icon svg { width: 20px; height: 20px; }
.stat .label { margin: 0; font-size: 12.5px; font-weight: 500; color: var(--muted); }
.stat .value { font-size: 20px; font-weight: 700; letter-spacing: -.02em; }
.tone-pending { background: var(--pending-soft); color: var(--pending); }
.tone-progress { background: var(--progress-soft); color: var(--progress); }
.tone-done { background: var(--done-soft); color: var(--done); }
.tone-accent { background: var(--accent-soft); color: var(--accent); }

/* ---------- Kanban ---------- */
.board { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 18px; align-items: start; }
.column { background: var(--column); border-radius: 16px; padding: 12px; min-width: 0; border: 1px solid rgba(0,0,0,.02); }
.column-head { display: flex; align-items: center; gap: 9px; padding: 4px 6px 12px; }
.column-head .dot { width: 9px; height: 9px; border-radius: 50%; }
.column-head h2 { font-size: 14px; font-weight: 650; }
.column-head .count { background: rgba(255,255,255,.8); color: var(--text-2); font-size: 12px; font-weight: 600; padding: 1px 8px; border-radius: 999px; }
.column-head .sum { margin-left: auto; font-size: 12.5px; font-weight: 600; color: var(--text-2); }
.column[data-status="pending"] .dot { background: var(--pending); }
.column[data-status="in_progress"] .dot { background: var(--progress); }
.column[data-status="completed"] .dot { background: var(--done); }
.dropzone { display: flex; flex-direction: column; gap: 10px; min-height: 140px; border-radius: 12px; transition: background .15s; }
.dropzone.is-over { background: rgba(91, 84, 232, .06); }
.empty {
  border: 1.5px dashed var(--border-strong); border-radius: 12px; padding: 26px 12px; text-align: center;
  color: var(--muted); font-size: 13px;
}
.dropzone:has(.task-card) .empty { display: none; }

.task-card {
  position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 12px;
  padding: 13px 14px 12px; box-shadow: var(--shadow-sm); cursor: grab; touch-action: manipulation;
  transition: box-shadow .15s, border-color .15s, transform .15s;
}
.task-card::before { content: ""; position: absolute; left: -1px; top: 12px; bottom: 12px; width: 3px; border-radius: 0 3px 3px 0; }
.column[data-status="pending"] .task-card::before { background: var(--pending); }
.column[data-status="in_progress"] .task-card::before { background: var(--progress); }
.column[data-status="completed"] .task-card::before { background: var(--done); }
.task-card:hover { box-shadow: var(--shadow); border-color: var(--border-strong); }
.task-card.locked { cursor: pointer; }
.task-card h3 { font-size: 14px; font-weight: 600; margin-bottom: 4px; padding-right: 70px; word-break: break-word; }
.task-card p { margin: 0 0 12px; color: var(--text-2); font-size: 13px; display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical; overflow: hidden; }
.task-card .amount { position: absolute; top: 12px; right: 13px; font-weight: 700; font-size: 13.5px; }
.task-meta { display: flex; align-items: center; justify-content: space-between; gap: 8px; color: var(--muted); font-size: 12px; }
.task-meta .who { display: flex; align-items: center; gap: 6px; min-width: 0; }
.task-meta .who span { white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.sortable-ghost { opacity: .35; border-style: dashed; box-shadow: none; }
.sortable-chosen { cursor: grabbing; }
.sortable-drag { transform: rotate(2deg); box-shadow: var(--shadow-lg) !important; }

.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; }
.toolbar .select { width: auto; height: 38px; min-width: 170px; }

/* ---------- Modal & drawer ---------- */
.overlay { position: fixed; inset: 0; z-index: 50; background: rgba(20, 23, 40, .42); backdrop-filter: blur(2px); display: grid; place-items: center; padding: 16px; animation: fade .15s ease-out; }
.modal { width: 100%; max-width: 520px; max-height: calc(100vh - 32px); overflow: auto; background: var(--surface); border-radius: 18px; box-shadow: var(--shadow-lg); animation: pop .18s ease-out; }
.modal-head { padding: 20px 24px 0; display: flex; justify-content: space-between; align-items: flex-start; gap: 12px; }
.modal-head h2 { font-size: 18px; font-weight: 700; }
.modal-head p { margin: 4px 0 0; color: var(--muted); font-size: 13.5px; }
.modal-body { padding: 20px 24px 8px; }
.modal-foot { padding: 14px 24px 20px; display: flex; justify-content: flex-end; gap: 10px; }
.modal-foot .spacer { flex: 1; }
.icon-btn { width: 32px; height: 32px; display: grid; place-items: center; border-radius: 8px; border: 0; background: none; color: var(--muted); cursor: pointer; flex: none; }
.icon-btn:hover { background: var(--column); color: var(--text); }
.icon-btn svg { width: 18px; height: 18px; }
.drawer-wrap { position: fixed; inset: 0; z-index: 50; background: rgba(20, 23, 40, .3); animation: fade .15s ease-out; }
.drawer { position: absolute; right: 0; top: 0; bottom: 0; width: min(460px, 100%); background: var(--surface); box-shadow: var(--shadow-lg); display: flex; flex-direction: column; animation: slide .2s ease-out; }
.drawer-body { padding: 4px 24px 24px; overflow: auto; flex: 1; }
.kv { display: grid; grid-template-columns: 110px 1fr; gap: 10px 12px; margin: 18px 0 22px; font-size: 13.5px; }
.kv dt { color: var(--muted); }
.kv dd { margin: 0; display: flex; align-items: center; gap: 8px; }
.prose { white-space: pre-wrap; color: var(--text-2); background: var(--surface-2); border: 1px solid var(--border); border-radius: 10px; padding: 12px 14px; font-size: 13.5px; }
.timeline { list-style: none; margin: 0; padding: 0; position: relative; }
.timeline li { position: relative; padding: 0 0 16px 22px; font-size: 13px; color: var(--text-2); }
.timeline li::before { content: ""; position: absolute; left: 4px; top: 6px; width: 8px; height: 8px; border-radius: 50%; background: var(--accent); box-shadow: 0 0 0 3px var(--accent-soft); }
.timeline li::after { content: ""; position: absolute; left: 7.5px; top: 18px; bottom: 0; width: 1px; background: var(--border); }
.timeline li:last-child::after { display: none; }
.timeline time { display: block; color: var(--muted); font-size: 12px; }
.section-title { font-size: 12px; text-transform: uppercase; letter-spacing: .06em; color: var(--muted); font-weight: 650; margin: 0 0 12px; }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
.table { width: 100%; border-collapse: collapse; font-size: 14px; }
.table th { text-align: left; font-size: 12px; font-weight: 600; text-transform: uppercase; letter-spacing: .05em; color: var(--muted); padding: 12px 22px; border-bottom: 1px solid var(--border); background: var(--surface-2); white-space: nowrap; }
.table td { padding: 14px 22px; border-bottom: 1px solid var(--border); vertical-align: middle; }
.table tr:last-child td { border-bottom: 0; }
.table tbody tr { transition: background .1s; }
.table tbody tr.link:hover { background: var(--surface-2); cursor: pointer; }
.table .right { text-align: right; }
.table th a { color: inherit; display: inline-flex; align-items: center; gap: 4px; }
.tabs { display: inline-flex; background: var(--column); border-radius: 10px; padding: 3px; gap: 2px; }
.tabs a { padding: 6px 12px; border-radius: 8px; color: var(--text-2); font-weight: 500; font-size: 13px; }
.tabs a.active { background: var(--surface); color: var(--text); box-shadow: var(--shadow-sm); }
.pagination { display: flex; gap: 6px; justify-content: flex-end; padding: 14px 22px; }

/* ---------- Invoice document ---------- */
.invoice-doc { padding: 40px 44px; }
.inv-top { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; margin-bottom: 34px; }
.inv-top h2 { font-size: 30px; font-weight: 750; letter-spacing: -.03em; }
.inv-parties { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 24px; margin-bottom: 30px; }
.inv-parties .addr { white-space: pre-line; font-size: 13.5px; color: var(--text-2); }
.inv-total { display: flex; justify-content: flex-end; padding: 18px 22px 4px; }
.inv-total div { min-width: 240px; display: flex; justify-content: space-between; font-size: 18px; font-weight: 700; }
.inv-foot { margin-top: 30px; padding-top: 18px; border-top: 1px solid var(--border); color: var(--muted); font-size: 13px; }
.audit { display: grid; gap: 6px; font-size: 13px; color: var(--text-2); }

/* ---------- Auth ---------- */
.auth { min-height: 100vh; display: grid; grid-template-columns: 1.05fr 1fr; }
.auth-art {
  position: relative; overflow: hidden; color: #fff; padding: 48px; display: flex; flex-direction: column; justify-content: space-between;
  background: radial-gradient(1200px 600px at -10% -20%, #8b85ff 0%, transparent 55%), radial-gradient(900px 500px at 120% 120%, #2dc8a0 0%, transparent 50%), linear-gradient(145deg, #3b35b8, #1d1a5e);
}
.auth-art .brand { color: #fff; }
.auth-art h2 { font-size: 34px; font-weight: 750; max-width: 440px; letter-spacing: -.03em; }
.auth-art p { color: rgba(255,255,255,.75); max-width: 420px; font-size: 15px; }
.mini-board { display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; max-width: 460px; margin-top: 28px; }
.mini-board div { background: rgba(255,255,255,.1); border: 1px solid rgba(255,255,255,.14); border-radius: 12px; padding: 10px; display: grid; gap: 8px; }
.mini-board span { height: 34px; border-radius: 8px; background: rgba(255,255,255,.18); }
.mini-board span:nth-child(2) { opacity: .7; }
.auth-form { display: grid; place-items: center; padding: 32px 20px; background: var(--surface); }
.auth-form .inner { width: 100%; max-width: 380px; }
.auth-form h1 { font-size: 26px; font-weight: 750; margin-bottom: 6px; }
.auth-form .lead { color: var(--muted); margin: 0 0 28px; }
.auth-row { display: flex; justify-content: space-between; align-items: center; margin: 4px 0 22px; font-size: 13.5px; }

/* ---------- Toast ---------- */
.toasts { position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%); z-index: 80; display: grid; gap: 8px; pointer-events: none; }
.toast { background: #1d2033; color: #fff; padding: 10px 16px; border-radius: 10px; box-shadow: var(--shadow-lg); font-weight: 500; font-size: 13.5px; animation: pop .18s ease-out; display: flex; gap: 8px; align-items: center; }
.toast.error { background: var(--danger); }

@keyframes fade { from { opacity: 0; } }
@keyframes pop { from { opacity: 0; transform: translateY(6px) scale(.98); } }
@keyframes slide { from { transform: translateX(30px); opacity: 0; } }

/* ---------- Responsive ---------- */
@media (max-width: 1100px) {
  .stats { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}
@media (max-width: 900px) {
  .auth { grid-template-columns: 1fr; }
  .auth-art { display: none; }
  .inv-parties { grid-template-columns: 1fr; gap: 16px; }
  .invoice-doc { padding: 26px 22px; }
}
@media (max-width: 820px) {
  .topbar-inner { padding: 0 16px; gap: 14px; }
  .usermenu .who { display: none; }
  .page { padding: 20px 16px 48px; }
  /* Columns become swipeable panes on phones. */
  .board { grid-template-columns: repeat(3, 86%); overflow-x: auto; scroll-snap-type: x mandatory; margin: 0 -16px; padding: 0 16px 8px; gap: 12px; }
  .column { scroll-snap-align: center; }
  .row { grid-template-columns: 1fr; gap: 0; }
  .table th, .table td { padding: 12px 14px; }
  .hide-sm { display: none; }
}
@media (max-width: 520px) {
  .brand span.name { display: none; }
  .stats { grid-template-columns: 1fr 1fr; gap: 10px; }
  .stat { padding: 12px; gap: 10px; }
  .stat-icon { display: none; }
  .stat .value { font-size: 17px; }
}

@media print {
  body { background: #fff; }
  .topbar, .no-print, .toasts { display: none !important; }
  .page { padding: 0; max-width: none; }
  .card { border: 0; box-shadow: none; }
  .invoice-doc { padding: 0; }
}
