/* ===== Tipolo Portal — app styles ===== */
/* Palette + type inherited from the Tipolo marketing site (css/styles.css). */

:root {
  --bg: #F5F2E9;
  --bg-alt: #EFEBDD;
  --ink: #242A20;
  --ink-soft: #565C4E;
  --ink-faint: #7C8A6B;
  --accent: #3F4A20;
  --accent-dark: #2C3616;
  --accent-rgb: 63, 74, 32;
  --border: #D8D3C4;
  --border-soft: #DCD7C9;
  --success-bg: #E7EDE0;
  --success-ink: #3F4B33;
  --error-bg: #F5E3DC;
  --error-ink: #7A3F1D;
  --warn-bg: #F6EED9;
  --warn-ink: #6E5A1E;
  --card-bg: #FFFFFF;
  --font-heading: 'Fredoka', ui-rounded, "Segoe UI", system-ui, sans-serif;
  --font-body: 'Roboto', "Segoe UI", system-ui, -apple-system, sans-serif;
  --radius: 10px;
  --radius-sm: 7px;
  --shadow: 0 1px 2px rgba(36, 42, 32, 0.06), 0 6px 20px rgba(36, 42, 32, 0.06);
  --sidebar-w: 224px;
}

* { box-sizing: border-box; margin: 0; padding: 0; }

html { -webkit-text-size-adjust: 100%; }

body {
  background: var(--bg);
  color: var(--ink);
  font-family: var(--font-body);
  line-height: 1.55;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3, h4 {
  font-family: var(--font-heading);
  font-weight: 500;
  letter-spacing: -0.01em;
  line-height: 1.2;
  color: var(--ink);
}
h1 { font-size: 1.5rem; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }
strong, b { font-weight: 500; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

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

/* ---------- boot / loading ---------- */
.boot {
  min-height: 100vh;
  display: grid;
  place-items: center;
  color: var(--ink-faint);
  font-family: var(--font-heading);
}

/* ---------- auth / login ---------- */
.auth-wrap {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 24px;
  background: radial-gradient(1200px 600px at 50% -10%, var(--bg-alt), var(--bg));
}
.auth-card {
  width: 100%;
  max-width: 380px;
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 30px 28px;
}
.auth-card .brand {
  font-family: var(--font-heading);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 1rem;
  color: var(--accent);
  margin-bottom: 4px;
}
.auth-card .brand span { color: var(--ink-soft); font-weight: 500; }
.auth-card h1 { font-size: 1.2rem; margin: 14px 0 4px; }
.auth-card p.sub { color: var(--ink-soft); font-size: 0.9rem; margin-bottom: 18px; }
.auth-card .field { margin-bottom: 14px; }
.auth-card .row-between {
  display: flex; justify-content: space-between; align-items: center;
  font-size: 0.85rem; margin-top: 6px;
}
.auth-switch { margin-top: 18px; font-size: 0.88rem; color: var(--ink-soft); }

/* ---------- form primitives ---------- */
label.lbl {
  display: block;
  font-size: 0.8rem;
  font-weight: 500;
  color: var(--ink-soft);
  margin-bottom: 5px;
}
.input,
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]):not([type=color]):not([type=submit]):not([type=button]),
select, textarea {
  width: 100%;
  padding: 9px 11px;
  background: var(--bg);
  color: var(--ink);
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  outline: none;
  font: inherit;
  transition: border-color .12s, box-shadow .12s;
}
input:not([type=checkbox]):not([type=radio]):not([type=range]):not([type=file]):not([type=color]),
textarea {
  -webkit-appearance: none;
  appearance: none;
}
.input:focus, input:focus, select:focus, textarea:focus {
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(var(--accent-rgb), 0.14);
}
/* keep autofilled fields on the form's cream background instead of the UA's white/blue */
input:-webkit-autofill,
input:-webkit-autofill:hover,
input:-webkit-autofill:focus {
  -webkit-text-fill-color: var(--ink);
  -webkit-box-shadow: 0 0 0 1000px var(--bg) inset;
  caret-color: var(--ink);
}
textarea { min-height: 88px; resize: vertical; }
.hint { font-size: 0.78rem; color: var(--ink-faint); margin-top: 4px; }
.field-error { font-size: 0.8rem; color: var(--error-ink); margin-top: 4px; }

.form-grid { display: grid; gap: 14px; }
.form-grid.cols-2 { grid-template-columns: 1fr 1fr; }
@media (max-width: 620px) { .form-grid.cols-2 { grid-template-columns: 1fr; } }

/* ---------- buttons ---------- */
.btn {
  display: inline-flex; align-items: center; gap: 7px;
  padding: 9px 15px;
  border: 1px solid transparent;
  border-radius: var(--radius-sm);
  background: var(--accent);
  color: #F5F2E9;
  font-weight: 500;
  cursor: pointer;
  transition: background .12s, border-color .12s, opacity .12s;
}
.btn:hover { background: var(--accent-dark); text-decoration: none; }
.btn:disabled { opacity: .55; cursor: default; }
.btn.block { width: 100%; justify-content: center; }
.btn.ghost { background: transparent; color: var(--ink); border-color: var(--border); }
.btn.ghost:hover { background: var(--bg-alt); }
.btn.subtle { background: var(--bg-alt); color: var(--ink); }
.btn.subtle:hover { background: var(--border-soft); }
.btn.danger { background: var(--error-ink); }
.btn.danger:hover { background: #63321a; }
.btn.sm { padding: 6px 10px; font-size: 0.85rem; }
.btn.link {
  background: none; border: none; color: var(--accent); padding: 0;
  font-weight: 500; cursor: pointer;
}
.btn.link:hover { text-decoration: underline; }

/* ---------- app shell ---------- */
.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}
.sidebar {
  background: var(--card-bg);
  border-right: 1px solid var(--border);
  padding: 20px 14px;
  display: flex;
  flex-direction: column;
  gap: 4px;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
}
.sidebar .brand {
  font-family: var(--font-heading);
  font-weight: 600;
  letter-spacing: 0.08em;
  text-transform: uppercase;
  font-size: 0.95rem;
  color: var(--accent);
  padding: 4px 10px 16px;
}
.sidebar .brand span { color: var(--ink-soft); font-weight: 500; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a {
  display: flex; align-items: center; gap: 10px;
  padding: 9px 10px;
  border-radius: var(--radius-sm);
  color: var(--ink-soft);
  font-size: 0.92rem;
}
.sidebar nav a:hover { background: var(--bg-alt); text-decoration: none; color: var(--ink); }
.sidebar nav a.active { background: var(--accent); color: #F5F2E9; }
.sidebar nav a .ic { width: 18px; text-align: center; opacity: .9; }
.sidebar .spacer { flex: 1; }
.sidebar .userbox {
  border-top: 1px solid var(--border-soft);
  padding-top: 12px;
  font-size: 0.82rem;
  color: var(--ink-faint);
}
.sidebar .userbox .email { color: var(--ink-soft); word-break: break-all; display: block; margin-bottom: 8px; }

.main { display: flex; flex-direction: column; min-width: 0; }
.topbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 14px 26px;
  border-bottom: 1px solid var(--border-soft);
  background: rgba(245, 242, 233, 0.85);
  backdrop-filter: blur(6px);
  position: sticky; top: 0; z-index: 20;
  min-height: 56px;
}
.topbar .crumbs { font-family: var(--font-heading); font-weight: 500; color: var(--ink); }
.topbar .actions { display: flex; align-items: center; gap: 10px; }
.view { padding: 24px 26px 60px; max-width: 1180px; width: 100%; }

@media (max-width: 820px) {
  .shell { grid-template-columns: 1fr; }
  .sidebar {
    position: sticky; top: 0; z-index: 30; height: auto;
    flex-direction: row; align-items: center; gap: 8px;
    padding: 10px 12px; overflow-x: auto;
  }
  .sidebar .brand { padding: 0 6px 0 2px; white-space: nowrap; flex-shrink: 0; }
  .sidebar .spacer { display: none; }
  .sidebar .userbox { border: none; padding-top: 0; margin-left: auto; flex-shrink: 0; }
  .sidebar .userbox .email { display: none; }
  .sidebar nav { flex-direction: row; gap: 4px; flex-shrink: 0; }
  .sidebar nav a { padding: 7px 10px; white-space: nowrap; }
  .sidebar nav a .ic { display: none; }
  .view { padding: 18px 16px 48px; }
}

/* ---------- cards / layout helpers ---------- */
.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px;
}
.card + .card { margin-top: 16px; }
.card h2 { margin-bottom: 12px; }
.stack { display: flex; flex-direction: column; gap: 16px; }
.cluster { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; }
.between { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.grid-cards { display: grid; gap: 14px; grid-template-columns: repeat(auto-fill, minmax(210px, 1fr)); }
.page-head { display: flex; justify-content: space-between; align-items: flex-start; gap: 16px; margin-bottom: 18px; }
.page-head .muted { color: var(--ink-soft); font-size: 0.9rem; margin-top: 2px; }
.muted { color: var(--ink-soft); }
.faint { color: var(--ink-faint); }
.right { text-align: right; }
.nowrap { white-space: nowrap; }
.mt-0 { margin-top: 0; }

/* ---------- stat tiles ---------- */
.stat {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px;
}
.stat .k { font-size: 0.78rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-faint); }
.stat .v { font-family: var(--font-heading); font-weight: 500; font-size: 1.5rem; margin-top: 4px; }
.stat .d { font-size: 0.82rem; color: var(--ink-soft); margin-top: 2px; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; border: 1px solid var(--border); border-radius: var(--radius); background: var(--card-bg); }
table.data { width: 100%; border-collapse: collapse; font-size: 0.92rem; }
table.data th, table.data td { padding: 10px 14px; text-align: left; border-bottom: 1px solid var(--border-soft); }
table.data th { font-size: 0.76rem; text-transform: uppercase; letter-spacing: .04em; color: var(--ink-faint); font-weight: 500; background: var(--bg-alt); position: sticky; top: 0; }
table.data tbody tr:last-child td { border-bottom: none; }
table.data tbody tr:hover { background: var(--bg-alt); }
table.data tr.clickable { cursor: pointer; }
table.data td.num, table.data th.num { text-align: right; font-variant-numeric: tabular-nums; }

.empty {
  text-align: center;
  padding: 40px 20px;
  color: var(--ink-faint);
}
.empty h3 { color: var(--ink-soft); margin-bottom: 6px; }

/* ---------- badges / chips ---------- */
.badge {
  display: inline-block;
  padding: 2px 9px;
  border-radius: 999px;
  font-size: 0.76rem;
  font-weight: 500;
  background: var(--bg-alt);
  color: var(--ink-soft);
  border: 1px solid var(--border-soft);
}
.badge.green { background: var(--success-bg); color: var(--success-ink); border-color: transparent; }
.badge.amber { background: var(--warn-bg); color: var(--warn-ink); border-color: transparent; }
.badge.red { background: var(--error-bg); color: var(--error-ink); border-color: transparent; }
.badge.grey { background: var(--bg-alt); color: var(--ink-faint); }

.filters { display: flex; flex-wrap: wrap; gap: 10px; align-items: center; margin-bottom: 14px; }
.filters .search { min-width: 200px; flex: 1 1 220px; max-width: 320px; }
.filters select { max-width: 200px; }
.seg { display: inline-flex; border: 1px solid var(--border); border-radius: var(--radius-sm); overflow: hidden; }
.seg button { padding: 7px 12px; background: var(--card-bg); border: none; cursor: pointer; font-size: 0.85rem; color: var(--ink-soft); }
.seg button + button { border-left: 1px solid var(--border); }
.seg button.on { background: var(--accent); color: #F5F2E9; }

/* ---------- dialog / modal ---------- */
dialog.modal {
  width: min(560px, calc(100vw - 32px));
  /* the global `* { margin: 0 }` reset kills the UA stylesheet's centering — restore it */
  position: fixed;
  inset: 0;
  margin: auto;
  max-height: calc(100vh - 48px);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 0;
  color: var(--ink);
  background: var(--card-bg);
  box-shadow: 0 20px 60px rgba(36, 42, 32, 0.28);
}
dialog.modal::backdrop { background: rgba(36, 42, 32, 0.38); }
dialog.modal .m-head { display: flex; justify-content: space-between; align-items: center; padding: 16px 18px; border-bottom: 1px solid var(--border-soft); }
dialog.modal .m-head h2 { margin: 0; }
dialog.modal .m-body { padding: 18px; max-height: 68vh; overflow-y: auto; }
dialog.modal .m-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 14px 18px; border-top: 1px solid var(--border-soft); background: var(--bg-alt); }
.icon-btn { background: none; border: none; cursor: pointer; color: var(--ink-faint); font-size: 1.1rem; line-height: 1; padding: 4px; }
.icon-btn:hover { color: var(--ink); }

/* ---------- alerts ---------- */
.alert { padding: 10px 12px; border-radius: var(--radius-sm); font-size: 0.9rem; }
.alert.error { background: var(--error-bg); color: var(--error-ink); }
.alert.success { background: var(--success-bg); color: var(--success-ink); }
.alert.info { background: var(--bg-alt); color: var(--ink-soft); }
.alert.warn { background: var(--warn-bg); color: var(--warn-ink); }

/* ---------- toast ---------- */
#toast-stack {
  position: fixed; right: 18px; bottom: 18px; z-index: 200;
  display: flex; flex-direction: column; gap: 8px; align-items: flex-end;
}
.toast {
  background: var(--ink);
  color: var(--bg);
  padding: 10px 14px;
  border-radius: var(--radius-sm);
  font-size: 0.88rem;
  box-shadow: var(--shadow);
  animation: toast-in .16s ease;
  max-width: 340px;
}
.toast.err { background: var(--error-ink); }
.toast.ok { background: var(--accent); }
@keyframes toast-in { from { opacity: 0; transform: translateY(6px); } }

/* ---------- misc ---------- */
.spinner {
  width: 16px; height: 16px; border-radius: 50%;
  border: 2px solid rgba(var(--accent-rgb), 0.25);
  border-top-color: var(--accent);
  animation: spin .7s linear infinite;
  display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }
.loading-row { display: flex; align-items: center; gap: 10px; color: var(--ink-faint); padding: 20px; }

.tabs { display: flex; gap: 4px; border-bottom: 1px solid var(--border); margin-bottom: 18px; }
.tabs a { padding: 9px 12px; color: var(--ink-soft); border-bottom: 2px solid transparent; font-size: 0.92rem; }
.tabs a:hover { text-decoration: none; color: var(--ink); }
.tabs a.active { color: var(--accent); border-bottom-color: var(--accent); }

.kv { display: grid; grid-template-columns: 140px 1fr; gap: 6px 14px; font-size: 0.92rem; }
.kv dt { color: var(--ink-faint); }
.kv dd { color: var(--ink); }

/* ---------- timer widget ---------- */
.timer-widget { display: flex; align-items: center; }
.timer-running {
  display: flex; align-items: center; gap: 8px;
  background: var(--bg-alt); border: 1px solid var(--border);
  border-radius: 999px; padding: 4px 6px 4px 12px; font-size: 0.85rem;
}
.timer-running .dot {
  width: 8px; height: 8px; border-radius: 50%; background: var(--error-ink);
  animation: pulse 1.6s ease-in-out infinite;
}
@keyframes pulse { 0%,100% { opacity: 1; } 50% { opacity: .35; } }
.timer-running .t-proj {
  max-width: 150px; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;
}
.timer-running .t-clock { font-variant-numeric: tabular-nums; font-weight: 500; }
@media (max-width: 820px) { .timer-running .t-proj { max-width: 90px; } }

/* ---------- timesheet week grid ---------- */
.week-grid {
  display: grid; grid-template-columns: repeat(7, 1fr); gap: 10px;
}
@media (max-width: 1000px) { .week-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px) { .week-grid { grid-template-columns: 1fr; } }
.day-block {
  background: var(--card-bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  overflow: hidden; display: flex; flex-direction: column;
}
.day-head {
  display: flex; justify-content: space-between; padding: 8px 10px;
  background: var(--bg-alt); font-size: 0.8rem; font-weight: 500;
  border-bottom: 1px solid var(--border-soft);
}
.day-empty { padding: 12px 10px; font-size: 0.82rem; }
.te-row {
  display: grid; grid-template-columns: 1fr auto; gap: 4px 8px;
  padding: 8px 10px; border-bottom: 1px solid var(--border-soft);
}
.te-row:last-child { border-bottom: none; }
.te-desc { font-size: 0.86rem; }
.te-meta { font-size: 0.76rem; margin-top: 2px; }
.te-dur { font-size: 0.86rem; font-variant-numeric: tabular-nums; align-self: start; }
.te-acts { grid-column: 1 / -1; display: flex; gap: 10px; }
.te-acts .btn.link { font-size: 0.78rem; }
.week-totals { margin-top: 14px; }

/* ---------- invoice editor totals ---------- */
.totals-box { display: flex; justify-content: flex-end; margin-top: 14px; }
.totals-box .totals { width: min(320px, 100%); font-size: 0.92rem; }
.totals-box .totals .row { display: flex; justify-content: space-between; padding: 4px 2px; }
.totals-box .totals .row.grand {
  border-top: 1.5px solid var(--accent); font-family: var(--font-heading);
  font-weight: 500; font-size: 1.05rem; margin-top: 4px; padding-top: 8px;
}
#lines input { padding: 6px 8px; }
#lines td { vertical-align: middle; }

/* ---------- proposal section blocks ---------- */
.sec-block {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 12px;
  margin-bottom: 12px;
  background: var(--bg-alt);
}
.sec-block:last-child { margin-bottom: 0; }
.sec-block h3 { margin-bottom: 4px; }
.sec-block textarea { background: var(--card-bg); }

/* ---------- client contact rows in the edit modal ---------- */
.contact-row {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius-sm);
  padding: 10px;
  background: var(--bg-alt);
}
.contact-row input { background: var(--card-bg); }

/* ---------- clients CRM table + notes timeline ---------- */
table.data.crm td { vertical-align: top; }
table.data.crm textarea {
  width: 100%; min-height: 44px; padding: 6px 8px; font-size: 0.88rem;
  background: var(--bg); border: 1px solid var(--border); border-radius: var(--radius-sm);
  resize: vertical;
}
table.data.crm textarea:focus { border-color: var(--accent); box-shadow: 0 0 0 3px rgba(var(--accent-rgb), .14); }
.note-entry { padding: 10px 0; border-bottom: 1px solid var(--border-soft); }
.note-entry:last-child { border-bottom: none; }
.note-entry.archived { opacity: 0.72; }
.note-entry.archived > div:last-child { font-size: 0.92rem; }
