/* =============================================================
   Design for Living :: application styles
   ============================================================= */

:root {
  --ink:        #1b1a18;
  --ink-soft:   #55524d;
  --ink-faint:  #8b8781;
  --line:       #e3ded6;
  --line-soft:  #efebe4;
  --paper:      #ffffff;
  --canvas:     #f7f5f1;
  --accent:     #8a6a3b;
  --accent-dk:  #6d5230;
  --accent-sft: #f2ead9;

  --green:      #1f7a4d;
  --green-bg:   #e6f4ec;
  --orange:     #b96a12;
  --orange-bg:  #fdf0e0;
  --red:        #b3261e;
  --red-bg:     #fbeae9;
  --blue:       #2a5d8f;
  --blue-bg:    #e8f0f8;

  --radius:     10px;
  --radius-sm:  6px;
  --shadow:     0 1px 2px rgba(27,26,24,.06), 0 8px 24px rgba(27,26,24,.05);
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--canvas);
  color: var(--ink);
  font: 15px/1.55 "Segoe UI", -apple-system, BlinkMacSystemFont, Roboto, Helvetica, Arial, sans-serif;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--accent-dk); text-decoration: none; }
a:hover { text-decoration: underline; }

h1, h2, h3, h4 { margin: 0 0 .5rem; font-weight: 600; letter-spacing: -.01em; }
h2 { font-size: 1.15rem; }
h3 { font-size: 1rem; }

/* ---------- Shell ---------- */
.shell { display: flex; min-height: 100vh; }

.sidebar {
  width: 236px;
  flex: 0 0 236px;
  background: var(--ink);
  color: #efeae1;
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.brand {
  display: flex;
  align-items: center;
  gap: .6rem;
  padding: 1.15rem 1.1rem;
  border-bottom: 1px solid rgba(255,255,255,.08);
}
.brand-mark {
  width: 34px; height: 34px;
  display: grid; place-items: center;
  background: var(--accent);
  color: #fff;
  border-radius: 8px;
  font-weight: 700;
  font-size: .78rem;
  letter-spacing: .02em;
}
.brand-text { font-size: .9rem; font-weight: 600; line-height: 1.2; }

.nav { padding: .75rem .6rem; flex: 1; overflow-y: auto; }
.nav-foot { padding: .6rem; border-top: 1px solid rgba(255,255,255,.08); }

.nav-link {
  display: block;
  padding: .5rem .7rem;
  margin-bottom: 2px;
  border-radius: var(--radius-sm);
  color: #cdc7bd;
  font-size: .88rem;
  text-decoration: none;
}
.nav-link:hover { background: rgba(255,255,255,.07); color: #fff; text-decoration: none; }
.nav-link.is-active { background: var(--accent); color: #fff; font-weight: 500; }
.nav-link--sub { font-size: .82rem; color: #a9a39a; }

/* ---------- Main ---------- */
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }

.topbar {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 1rem;
  padding: .9rem 1.5rem;
  background: var(--paper);
  border-bottom: 1px solid var(--line);
  position: sticky; top: 0; z-index: 20;
}
.page-title { font-size: 1.12rem; margin: 0; }
.topbar-actions { display: flex; align-items: center; gap: .65rem; }

.user-chip { text-align: right; line-height: 1.15; }
.user-name { display: block; font-size: .84rem; font-weight: 600; }
.user-role { display: block; font-size: .72rem; color: var(--ink-faint); }

.content { padding: 1.5rem; flex: 1; }

/* ---------- Flash ---------- */
.flash-stack { padding: .9rem 1.5rem 0; }
.flash-stack--floating { position: fixed; top: 1rem; left: 50%; transform: translateX(-50%); z-index: 50; padding: 0; }
.flash {
  padding: .65rem .9rem;
  border-radius: var(--radius-sm);
  font-size: .88rem;
  margin-bottom: .5rem;
  border: 1px solid transparent;
}
.flash--success { background: var(--green-bg);  color: var(--green);  border-color: #bfe0cd; }
.flash--error   { background: var(--red-bg);    color: var(--red);    border-color: #f0c9c6; }
.flash--info    { background: var(--blue-bg);   color: var(--blue);   border-color: #c8dbec; }

/* ---------- Cards ---------- */
.card {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  margin-bottom: 1.25rem;
  overflow: hidden;
}
.card-head {
  display: flex; align-items: center; justify-content: space-between; gap: 1rem;
  padding: .85rem 1.1rem;
  border-bottom: 1px solid var(--line-soft);
}
.card-head h2, .card-head h3 { margin: 0; }
.card-body { padding: 1.1rem; }
.card-body--flush { padding: 0; }

.muted { color: var(--ink-faint); }
.small { font-size: .82rem; }
.mono  { font-family: ui-monospace, "Cascadia Mono", Consolas, monospace; }
.right { text-align: right; }
.center{ text-align: center; }
.nowrap{ white-space: nowrap; }

/* ---------- Stat tiles ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(160px, 1fr));
  gap: .9rem;
  margin-bottom: 1.25rem;
}
.stat {
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: .9rem 1rem;
  box-shadow: var(--shadow);
}
.stat-label { font-size: .74rem; text-transform: uppercase; letter-spacing: .05em; color: var(--ink-faint); }
.stat-value { font-size: 1.65rem; font-weight: 650; line-height: 1.15; margin-top: .15rem; }
.stat-note  { font-size: .78rem; color: var(--ink-soft); }
.stat--green  .stat-value { color: var(--green); }
.stat--orange .stat-value { color: var(--orange); }
.stat--red    .stat-value { color: var(--red); }

/* ---------- Tables ---------- */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: .88rem;
}
table.data th {
  text-align: left;
  font-weight: 600;
  font-size: .74rem;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--ink-faint);
  padding: .6rem .8rem;
  border-bottom: 1px solid var(--line);
  background: #fbfaf7;
  white-space: nowrap;
}
table.data td {
  padding: .62rem .8rem;
  border-bottom: 1px solid var(--line-soft);
  vertical-align: middle;
}
table.data tbody tr:hover { background: #fcfbf8; }
table.data tfoot td { font-weight: 600; border-top: 2px solid var(--line); }
.empty-row td { padding: 2rem; text-align: center; color: var(--ink-faint); }

/* ---------- Badges & flags ---------- */
.badge {
  display: inline-block;
  padding: .16rem .5rem;
  border-radius: 999px;
  font-size: .72rem;
  font-weight: 600;
  letter-spacing: .01em;
  background: var(--line-soft);
  color: var(--ink-soft);
  white-space: nowrap;
}
.badge--green  { background: var(--green-bg);  color: var(--green); }
.badge--orange { background: var(--orange-bg); color: var(--orange); }
.badge--red    { background: var(--red-bg);    color: var(--red); }
.badge--blue   { background: var(--blue-bg);   color: var(--blue); }
.badge--accent { background: var(--accent-sft);color: var(--accent-dk); }

.dot { display: inline-block; width: 9px; height: 9px; border-radius: 50%; margin-right: .4rem; }
.dot--green  { background: var(--green); }
.dot--orange { background: var(--orange); }
.dot--red    { background: var(--red); }
.dot--neutral{ background: var(--ink-faint); }

tr.row--red    { background: var(--red-bg); }
tr.row--orange { background: var(--orange-bg); }
tr.row--red:hover    { background: #f8dedc; }
tr.row--orange:hover { background: #fbe7d2; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex;
  align-items: center;
  gap: .35rem;
  padding: .45rem .85rem;
  border-radius: var(--radius-sm);
  border: 1px solid var(--line);
  background: var(--paper);
  color: var(--ink);
  font-size: .85rem;
  font-weight: 500;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.4;
}
.btn:hover { background: #faf8f4; text-decoration: none; }
.btn-primary { background: var(--accent); border-color: var(--accent); color: #fff; }
.btn-primary:hover { background: var(--accent-dk); border-color: var(--accent-dk); }
.btn-dark { background: var(--ink); border-color: var(--ink); color: #fff; }
.btn-dark:hover { background: #2e2c29; }
.btn-ghost { background: transparent; border-color: transparent; color: var(--ink-soft); }
.btn-ghost:hover { background: var(--line-soft); }
.btn-danger { color: var(--red); border-color: #f0c9c6; background: var(--red-bg); }
.btn-sm { padding: .28rem .6rem; font-size: .78rem; }
.btn[disabled], .btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-row { display: flex; gap: .5rem; flex-wrap: wrap; align-items: center; }

/* ---------- Forms ---------- */
.field { margin-bottom: .9rem; }
.field label {
  display: block;
  font-size: .78rem;
  font-weight: 600;
  color: var(--ink-soft);
  margin-bottom: .28rem;
}
.field .hint { font-size: .76rem; color: var(--ink-faint); margin-top: .22rem; }

input[type=text], input[type=email], input[type=password], input[type=number],
input[type=date], input[type=search], input[type=tel], select, textarea {
  width: 100%;
  padding: .48rem .6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  background: var(--paper);
  color: var(--ink);
  font: inherit;
  font-size: .88rem;
}
input:focus, select:focus, textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px rgba(138,106,59,.14);
}
textarea { min-height: 72px; resize: vertical; }
input[readonly] { background: #f6f4f0; color: var(--ink-soft); }

.checkline { display: flex; align-items: center; gap: .45rem; font-size: .86rem; }
.checkline input { width: auto; }

.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 0 1rem; }
.grid-3 { display: grid; grid-template-columns: repeat(auto-fit, minmax(170px, 1fr)); gap: 0 1rem; }
.split  { display: grid; grid-template-columns: 2fr 1fr; gap: 1.25rem; align-items: start; }
@media (max-width: 1000px) { .split { grid-template-columns: 1fr; } }

/* ---------- Filter bar ---------- */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: .6rem;
  align-items: flex-end;
  padding: .85rem 1.1rem;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  margin-bottom: 1.1rem;
}
.filters .field { margin: 0; min-width: 150px; }
.filters .field--grow { flex: 1; min-width: 220px; }

/* ---------- Definition list ---------- */
.dl { display: grid; grid-template-columns: max-content 1fr; gap: .4rem 1.1rem; font-size: .88rem; }
.dl dt { color: var(--ink-faint); font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; padding-top: .1rem; }
.dl dd { margin: 0; font-weight: 500; }

/* ---------- Pipeline ---------- */
.pipeline { display: flex; gap: .5rem; flex-wrap: wrap; }
.pipeline-step {
  flex: 1 1 130px;
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  padding: .6rem .7rem;
  background: var(--paper);
}
.pipeline-step.is-current { border-color: var(--accent); background: var(--accent-sft); }
.pipeline-step .n { font-size: 1.3rem; font-weight: 650; }
.pipeline-step .l { font-size: .74rem; color: var(--ink-faint); text-transform: uppercase; letter-spacing: .04em; }

.progress { height: 6px; background: var(--line-soft); border-radius: 999px; overflow: hidden; }
.progress > span { display: block; height: 100%; background: var(--accent); }

.timeline { list-style: none; margin: 0; padding: 0; }
.timeline li {
  position: relative;
  padding: 0 0 .9rem 1.3rem;
  border-left: 2px solid var(--line);
  margin-left: .35rem;
}
.timeline li:last-child { border-left-color: transparent; padding-bottom: 0; }
.timeline li::before {
  content: ''; position: absolute; left: -6px; top: .35rem;
  width: 10px; height: 10px; border-radius: 50%;
  background: var(--accent); border: 2px solid var(--paper);
}

/* ---------- Loan desk ---------- */
.scan-box {
  display: flex; gap: .5rem; align-items: center;
  padding: 1rem;
  background: var(--accent-sft);
  border: 1px dashed var(--accent);
  border-radius: var(--radius);
  margin-bottom: 1rem;
}
.scan-box input {
  font-size: 1.05rem;
  font-family: ui-monospace, Consolas, monospace;
  letter-spacing: .04em;
}
.scan-feedback { font-size: .85rem; min-height: 1.3rem; }
.scan-feedback.is-error { color: var(--red); }
.scan-feedback.is-ok { color: var(--green); }

/* ---------- Login ---------- */
.body-centered { display: grid; place-items: center; min-height: 100vh; background: var(--ink); }
.login-card {
  width: min(380px, 92vw);
  background: var(--paper);
  border-radius: 14px;
  padding: 2rem 1.9rem;
  box-shadow: 0 20px 60px rgba(0,0,0,.35);
}
.login-brand { text-align: center; margin-bottom: 1.4rem; }
.login-brand .mark {
  width: 48px; height: 48px; margin: 0 auto .7rem;
  display: grid; place-items: center;
  background: var(--accent); color: #fff;
  border-radius: 12px; font-weight: 700;
}
.login-brand h1 { font-size: 1.15rem; margin: 0; }
.login-brand p { margin: .2rem 0 0; font-size: .82rem; color: var(--ink-faint); }

/* ---------- Misc ---------- */
.section-title {
  font-size: .76rem; text-transform: uppercase; letter-spacing: .06em;
  color: var(--ink-faint); font-weight: 600; margin: 1.4rem 0 .6rem;
}
.notice {
  padding: .7rem .9rem;
  border-radius: var(--radius-sm);
  font-size: .85rem;
  border: 1px solid var(--line);
  background: #fbfaf7;
  margin-bottom: 1rem;
}
.notice--warn { background: var(--orange-bg); border-color: #f0d4ae; color: var(--orange); }
.notice--lock { background: var(--blue-bg); border-color: #c8dbec; color: var(--blue); }

.error-page { max-width: 460px; margin: 4rem auto; text-align: center; }
.error-page .code { font-size: 3rem; font-weight: 700; color: var(--ink-faint); }

.label-sheet { display: grid; grid-template-columns: repeat(3, 1fr); gap: .4rem; }

/* ---------- Catalog typeahead ---------- */
.picker { position: relative; }
.picker-results {
  display: none;
  position: absolute;
  z-index: 30;
  top: calc(100% + 4px);
  left: 0; right: 0;
  max-height: 300px;
  overflow-y: auto;
  background: var(--paper);
  border: 1px solid var(--line);
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow);
}
.picker-item {
  display: block;
  width: 100%;
  text-align: left;
  padding: .5rem .7rem;
  border: 0;
  border-bottom: 1px solid var(--line-soft);
  background: transparent;
  font: inherit;
  font-size: .85rem;
  cursor: pointer;
}
.picker-item:last-child { border-bottom: 0; }
.picker-item:hover:not([disabled]) { background: var(--accent-sft); }
.picker-item[disabled] { opacity: .65; cursor: not-allowed; }
.picker-empty { padding: .7rem; }

/* ---------- Line editor table ---------- */
table.lines { width: 100%; border-collapse: collapse; font-size: .86rem; }
table.lines th {
  text-align: left; font-size: .72rem; text-transform: uppercase; letter-spacing: .04em;
  color: var(--ink-faint); padding: .5rem .5rem; border-bottom: 1px solid var(--line);
  background: #fbfaf7; white-space: nowrap;
}
table.lines td { padding: .35rem .4rem; border-bottom: 1px solid var(--line-soft); vertical-align: middle; }
table.lines input, table.lines select { padding: .35rem .45rem; font-size: .84rem; }
table.lines tfoot td { font-weight: 600; border-top: 2px solid var(--line); }
table.lines .col-idx { width: 34px; color: var(--ink-faint); text-align: center; }
table.lines .col-qty { width: 110px; }
table.lines .col-uom { width: 80px; }
table.lines .col-cost { width: 120px; }
table.lines .col-total { width: 110px; text-align: right; font-variant-numeric: tabular-nums; }
table.lines .col-act { width: 60px; text-align: right; }

/* ---------- Nav: child entries (Collections under Sample Books) ---------- */
.nav-link--child { padding-left: 1.7rem; font-size: .83rem; position: relative; }
.nav-link--child::before {
  content: ''; position: absolute; left: 1.05rem; top: 50%;
  width: 6px; height: 1px; background: currentColor; opacity: .45;
}
