/* Caledonia Books — corporate product UI. Independent of Direct. */

@import url("https://fonts.googleapis.com/css2?family=IBM+Plex+Sans:ital,wght@0,400;0,500;0,600;0,700;1,400&display=swap");

:root {
  --ink: #12151a;
  --ink-soft: #3d4450;
  --muted: #6b7380;
  --line: #e6e9ee;
  --line-strong: #d0d5dd;
  --paper: #ffffff;
  --canvas: #f4f6f8;
  --sidebar: #0b1220;
  --sidebar-2: #111a2b;
  --accent: #1b4f72;
  --accent-hover: #163e5a;
  --accent-soft: rgba(27, 79, 114, 0.1);
  --hair: #c5cdd6;
  --danger: #b42318;
  --danger-bg: #fef3f2;
  --danger-line: #fecdca;
  --success: #0b6e4f;
  --success-bg: #ecfdf3;
  --success-line: #abefc6;
  --warn: #9a6700;
  --warn-bg: #fffaeb;
  --radius: 8px;
  --radius-sm: 6px;
  --sidebar-w: 232px;
  --shadow: 0 1px 2px rgba(18, 21, 26, 0.04), 0 8px 24px rgba(18, 21, 26, 0.04);
  --font: "IBM Plex Sans", "Segoe UI", system-ui, -apple-system, sans-serif;
}

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

html {
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

body {
  margin: 0;
  min-height: 100vh;
  font-family: var(--font);
  font-size: 14.5px;
  line-height: 1.5;
  color: var(--ink);
  background: var(--canvas);
}

img { max-width: 100%; height: auto; display: block; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; text-underline-offset: 2px; }

h1, h2, h3 {
  font-family: var(--font);
  color: var(--ink);
  line-height: 1.25;
  margin: 0 0 0.5rem;
  font-weight: 600;
  letter-spacing: -0.02em;
}
h1 { font-size: 1.35rem; }
h2 { font-size: 1.02rem; }
h3 { font-size: 0.92rem; }
p { margin: 0 0 0.85rem; }

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.35rem;
  padding: 0.48rem 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-size: 0.875rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none !important;
  letter-spacing: -0.01em;
}
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-primary {
  background: var(--accent);
  color: #fff !important;
  border-color: var(--accent);
}
.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }
.btn-outline {
  background: #fff;
  color: var(--ink) !important;
  border-color: var(--line-strong);
}
.btn-outline:hover { border-color: var(--accent); color: var(--accent) !important; background: var(--accent-soft); }
.btn-sm { padding: 0.28rem 0.65rem; font-size: 0.78rem; }
.btn-block { width: 100%; }
.inline { display: inline-block; margin: 0; }

.app-shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) 1fr;
  min-height: 100vh;
}

.nav-toggle { position: absolute; opacity: 0; pointer-events: none; width: 0; height: 0; }
.nav-open, .nav-close, .nav-backdrop { display: none; }

.sidebar-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 0.5rem;
  padding: 0 0.15rem;
}

.app-sidebar {
  background: var(--sidebar);
  color: #fff;
  padding: 1.15rem 0.85rem 1rem;
  display: flex;
  flex-direction: column;
  gap: 1.4rem;
  position: sticky;
  top: 0;
  height: 100vh;
  overflow-y: auto;
  overflow-x: hidden;
  border-right: 1px solid #1a2436;
}

.books-brand {
  display: flex;
  align-items: center;
  gap: 0.7rem;
  min-width: 0;
  text-decoration: none !important;
  color: #fff !important;
}
.books-brand .mark {
  flex: 0 0 32px;
  width: 32px;
  height: 32px;
  display: block;
  border-radius: 6px;
}
.books-brand .brand-mark {
  display: flex;
  flex-direction: column;
  min-width: 0;
  line-height: 1.15;
}
.books-brand .brand-mark strong {
  color: #f3f5f8;
  font-size: 0.92rem;
  font-weight: 600;
  letter-spacing: 0.01em;
  white-space: nowrap;
}
.books-brand .brand-mark span {
  color: #8aa0b8;
  font-size: 0.68rem;
  font-weight: 500;
  letter-spacing: 0.14em;
  text-transform: uppercase;
  white-space: nowrap;
}

.side-nav {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 0.1rem;
}
.side-nav a {
  display: flex;
  align-items: center;
  gap: 0.55rem;
  padding: 0.48rem 0.7rem;
  border-radius: 6px;
  color: #c5d0dc;
  text-decoration: none;
  font-size: 0.875rem;
  font-weight: 500;
}
.side-nav a:hover {
  background: rgba(255, 255, 255, 0.05);
  color: #fff;
  text-decoration: none;
}
.side-nav a.active {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
  box-shadow: inset 2px 0 0 #7ea4c4;
}
.side-nav .nav-icon {
  display: none;
}

.side-footer {
  margin-top: auto;
  padding: 0.85rem 0.7rem 0.2rem;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
  font-size: 0.78rem;
  color: #8aa0b8;
}
.side-footer a { color: #b7c8d8; text-decoration: none; }
.side-footer a:hover { color: #fff; }

.app-main { display: flex; flex-direction: column; min-width: 0; background: var(--canvas); }

.app-topbar {
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  padding: 0.85rem 1.5rem;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  flex-wrap: wrap;
  position: sticky;
  top: 0;
  z-index: 20;
}
.topbar-left { display: flex; align-items: center; gap: 0.75rem; min-width: 0; }
.app-topbar .eyebrow {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.1em;
  color: var(--muted);
  margin: 0 0 0.12rem;
  font-weight: 600;
}
.app-topbar h1 { margin: 0; font-size: 1.2rem; font-weight: 600; }

.app-content {
  padding: 1.35rem 1.5rem 2.5rem;
  max-width: 1180px;
  width: 100%;
}

.topbar-filters { display: flex; align-items: center; gap: 0.75rem; flex-wrap: wrap; }
.period-form label {
  flex-direction: row;
  align-items: center;
  gap: 0.45rem;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--muted);
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.period-form input[type="month"] {
  padding: 0.28rem 0.45rem;
  font-size: 0.85rem;
  font-weight: 500;
}

.unit-switch, .filter-bar { display: flex; flex-wrap: wrap; gap: 0.3rem; margin-bottom: 0.9rem; }
.chip {
  display: inline-flex;
  align-items: center;
  padding: 0.28rem 0.72rem;
  border-radius: 999px;
  border: 1px solid var(--line-strong);
  color: var(--ink-soft);
  font-size: 0.78rem;
  font-weight: 600;
  text-decoration: none !important;
  background: #fff;
}
.chip:hover { border-color: var(--accent); color: var(--accent); }
.chip.on { background: var(--sidebar); color: #fff !important; border-color: var(--sidebar); }

.panel {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 1.1rem 1.2rem;
}
.panel + .panel { margin-top: 0.9rem; }
.panel-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 0.85rem;
  flex-wrap: wrap;
}
.panel-header h2 { margin: 0; }

.stats-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: 0.75rem;
  margin-bottom: 1.1rem;
}
.stat-card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 0.9rem 1rem;
}
.stat-card .label {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--muted);
  margin: 0 0 0.3rem;
  font-weight: 600;
}
.stat-card .value {
  font-size: 1.35rem;
  font-weight: 600;
  color: var(--ink);
  margin: 0;
  letter-spacing: -0.03em;
  font-variant-numeric: tabular-nums;
}
.stat-card .hint { font-size: 0.78rem; color: var(--muted); margin: 0.2rem 0 0; }
.stat-card.accent { background: var(--sidebar); border-color: var(--sidebar); color: #fff; }
.stat-card.accent .label, .stat-card.accent .hint { color: #8aa0b8; }
.stat-card.accent .value { color: #fff; }

.table-wrap { overflow-x: auto; max-width: 100%; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.875rem;
}
table.data th, table.data td {
  padding: 0.62rem 0.7rem;
  text-align: left;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.data th {
  font-size: 0.68rem;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--muted);
  font-weight: 600;
  background: #fafbfc;
}
table.data tbody tr:hover { background: #f7f9fb; }
table.data .num { text-align: right; font-variant-numeric: tabular-nums; }
table.data td select { width: auto; min-width: 9rem; max-width: 100%; }
tr.total td { font-weight: 600; border-top: 1px solid var(--line-strong); background: #fafbfc; }

.form-stack { display: flex; flex-direction: column; gap: 0.8rem; }
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 0.8rem;
}
label {
  display: flex;
  flex-direction: column;
  gap: 0.3rem;
  font-size: 0.78rem;
  font-weight: 600;
  color: var(--ink-soft);
}
input[type="text"], input[type="email"], input[type="password"], input[type="number"],
input[type="date"], input[type="month"], input[type="search"], input[type="file"],
select, textarea {
  font: inherit;
  font-weight: 400;
  color: var(--ink);
  background: #fff;
  border: 1px solid var(--line-strong);
  border-radius: var(--radius-sm);
  padding: 0.48rem 0.65rem;
  width: 100%;
}
input:focus, select:focus, textarea:focus {
  outline: 2px solid var(--accent-soft);
  border-color: var(--accent);
}
textarea { min-height: 100px; resize: vertical; }
label.check { flex-direction: row; align-items: center; font-weight: 500; }
label.check input { width: auto; }

.alert {
  padding: 0.7rem 0.95rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  margin-bottom: 1rem;
  font-size: 0.875rem;
}
.alert-error { background: var(--danger-bg); border-color: var(--danger-line); color: var(--danger); }
.alert-success { background: var(--success-bg); border-color: var(--success-line); color: var(--success); }

.amt { font-variant-numeric: tabular-nums; }
.amt-neg { color: var(--danger); }
.amt-pos { color: var(--success); }
.amt-zero { color: var(--muted); }
.muted, .note { color: var(--muted); font-size: 0.84rem; }
.gross, .net { font-weight: 600; color: var(--ink); letter-spacing: -0.02em; }

.pl-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(240px, 1fr)); gap: 0.9rem; }
.pl-col h2 { font-size: 0.95rem; }

.cat-form { display: flex; flex-wrap: wrap; gap: 0.25rem; align-items: center; }
.cat-form select { min-width: 8rem; max-width: 12rem; }

.invite-banner {
  background: #fff;
  border: 1px solid var(--accent);
  border-left: 3px solid var(--accent);
  border-radius: var(--radius);
  padding: 1rem 1.15rem;
  margin-bottom: 1rem;
}
.invite-banner h2 { margin: 0 0 0.3rem; }
.invite-link { display: flex; gap: 0.4rem; align-items: center; flex-wrap: wrap; }
.invite-link input {
  flex: 1 1 16rem;
  min-width: 12rem;
  font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
  font-size: 0.78rem;
}
tr.invite-new { background: var(--accent-soft); }

.nav-badge {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 1.15rem;
  height: 1.15rem;
  padding: 0 0.32rem;
  margin-left: auto;
  border-radius: 999px;
  background: #c2410c;
  color: #fff;
  font-size: 0.68rem;
  font-weight: 700;
}

.feedback-box {
  margin-top: 2.75rem;
  padding-top: 1.1rem;
  border-top: 1px solid var(--line);
  max-width: 36rem;
}
.feedback-box summary {
  cursor: pointer;
  font-weight: 600;
  color: var(--ink-soft);
  font-size: 0.84rem;
}
.feedback-box details[open] summary { margin-bottom: 0.6rem; color: var(--ink); }
.feedback-box textarea { min-height: 4.5rem; }

.feedback-item {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1rem 1.1rem;
  margin-bottom: 0.7rem;
}
.feedback-item.status-new { border-left: 3px solid var(--accent); }
.feedback-item.status-done { opacity: 0.7; }
.feedback-actions { display: flex; gap: 0.4rem; flex-wrap: wrap; margin-top: 0.55rem; }

/* Auth — quiet, centered, corporate */
body.auth-body { background: var(--canvas); }
.auth-page {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 2rem 1rem;
}
.auth-wrap { width: 100%; max-width: 400px; }
.auth-wrap .books-brand { margin-bottom: 1.5rem; color: var(--ink) !important; }
.auth-wrap .books-brand .brand-mark strong { color: var(--ink); font-size: 1.05rem; }
.auth-wrap .books-brand .brand-mark span { color: var(--muted); }
.auth-card {
  background: #fff;
  border: 1px solid var(--line);
  border-radius: 10px;
  box-shadow: var(--shadow);
  padding: 1.6rem 1.5rem 1.4rem;
}
.auth-card h2 { margin: 0 0 0.25rem; font-size: 1.2rem; }
.auth-card .lede { color: var(--muted); margin-bottom: 1.25rem; }
.auth-foot { margin-top: 1.25rem; font-size: 0.8rem; color: var(--muted); text-align: center; }

@media (max-width: 900px) {
  .app-shell { grid-template-columns: 1fr; }
  .nav-open {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.4rem 0.65rem;
    border-radius: var(--radius-sm);
    border: 1px solid var(--line-strong);
    background: #fff;
    color: var(--ink);
    font-size: 0.8rem;
    font-weight: 600;
    cursor: pointer;
  }
  .nav-open-bars {
    width: 1rem;
    height: 0.8rem;
    display: inline-block;
    background:
      linear-gradient(var(--ink), var(--ink)) 0 0 / 100% 1.5px no-repeat,
      linear-gradient(var(--ink), var(--ink)) 0 50% / 100% 1.5px no-repeat,
      linear-gradient(var(--ink), var(--ink)) 0 100% / 100% 1.5px no-repeat;
  }
  .nav-close {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 2rem;
    height: 2rem;
    color: #fff;
    cursor: pointer;
  }
  .nav-backdrop {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(11, 18, 32, 0.45);
    z-index: 40;
  }
  .app-sidebar {
    position: fixed;
    top: 0; left: 0; bottom: 0;
    width: min(84vw, 260px);
    z-index: 50;
    transform: translateX(-105%);
    transition: transform 0.2s ease;
  }
  .nav-toggle:checked ~ .app-sidebar { transform: translateX(0); }
  .nav-toggle:checked ~ .nav-backdrop { display: block; }
  .pl-grid { grid-template-columns: 1fr; }
}
