/*
 * Shemify Close Books — Tracker #26 v1
 * Page-scoped styles for Accounting → Close Books.
 *
 * Lessons applied from Trackers #10 + #20 — locked in BEFORE first commit:
 *   - NO max-width; full-width like every other Accounting page
 *   - NO custom .cb-modal-* CSS; defer to global .modal-overlay system
 *     in /app/ui-components.css for orbs/blur/spring/parallax/stagger
 *   - .ui-dropdown { width: auto } scoped to #close-books-host to override
 *     /app/ui-components.css :466 .ui-dropdown { width: 100% }
 *   - 13px KPI label, 44×44 modal close, focus rings WCAG AA 3:1
 *   - !important on form-input :hover/:focus/.is-saved/.is-error to win
 *     the cascade vs `shell-override-v2.css :540-547` global !important
 *     (the phase20_c hotfix learning)
 *   - .cb-modal marker class on overlays for page-specific tweaks
 *   - Tab + Enter + Esc keyboard handling parity with budgets grid
 */

.cb-page {
  padding: 24px 32px;
  width: 100%;
  box-sizing: border-box;
  color: var(--ink);
  font: 400 14px/1.5 var(--font);
}

/* ──────────────────────────────────────────────────────────────────────
 * Section heads + titles
 * ────────────────────────────────────────────────────────────────────── */
.cb-section-head {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin: 0 0 12px;
  flex-wrap: wrap;
}
.cb-title-wrap { display: flex; align-items: center; gap: 10px; }
.cb-section-title {
  font: 700 22px/1.2 var(--font);
  letter-spacing: -.025em;
  color: var(--ink);
  text-shadow: 0 0 30px rgba(200, 160, 76, .06);
}
.cb-help-btn {
  width: 44px; height: 44px;
  border: none;
  border-radius: 50%;
  background: var(--raised);
  color: var(--ink-3);
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06);
  transition: all .2s var(--spring);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.cb-help-btn:hover { color: var(--gold); transform: scale(1.05); box-shadow: inset 0 0 0 1px var(--gold-glow-ring); }
html.light .cb-help-btn {
  background: rgba(0, 0, 0, .04);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06);
}
.cb-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }
.cb-page-desc {
  margin: 0 0 16px;
  max-width: 720px;
  font-size: 13px;
  color: var(--ink-2);
  line-height: 1.5;
}

/* Buttons */
.cb-btn {
  min-height: 44px;
  padding: 11px 20px;
  border-radius: var(--r-sm);
  border: none;
  cursor: pointer;
  font: 600 13px var(--font);
  letter-spacing: -.005em;
  transition: all .22s var(--spring);
  display: inline-flex;
  align-items: center;
  justify-content: center;
}
.cb-btn-primary {
  background: linear-gradient(135deg, var(--gold-bright) 0%, var(--gold) 100%);
  color: var(--void);
  box-shadow: 0 2px 12px rgba(200, 160, 76, .25), 0 0 30px rgba(200, 160, 76, .1), inset 0 1px 0 rgba(255, 255, 255, .2);
}
.cb-btn-primary:hover { transform: translateY(-2px) scale(1.02); box-shadow: 0 6px 28px rgba(200, 160, 76, .4), 0 0 60px rgba(200, 160, 76, .15), inset 0 1px 0 rgba(255, 255, 255, .25); }
.cb-btn-primary[disabled] {
  opacity: .55; cursor: not-allowed; transform: none;
  box-shadow: none; background: rgba(255, 255, 255, .06); color: var(--ink-3);
  filter: grayscale(1);
}
.cb-btn-ghost {
  background: rgba(255, 255, 255, .05); color: var(--ink);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08), 0 2px 8px rgba(0, 0, 0, .2);
}
.cb-btn-ghost:hover { background: rgba(255, 255, 255, .09); transform: translateY(-1px) scale(1.01); }
html.light .cb-btn-ghost { background: rgba(0, 0, 0, .04); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08); color: var(--ink); }
.cb-btn-danger { background: var(--red-glow); color: var(--red); box-shadow: inset 0 0 0 1px rgba(248, 113, 113, .25); }

.cb-role-hint {
  font-size: 11px; color: var(--ink-3); letter-spacing: .02em;
}
.cb-export-disabled-wrap {
  position: relative; display: inline-flex; align-items: center;
}
.cb-export-disabled-wrap .cb-role-hint {
  position: absolute; bottom: -18px; right: 0; white-space: nowrap;
}

/* KPI strip — 13px label */
.cb-kpi-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
  gap: 16px;
  margin: 20px 0;
}
.cb-kpi {
  padding: 20px 22px;
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, rgba(255, 255, 255, .03) 0%, rgba(255, 255, 255, .015) 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .05), 0 2px 8px rgba(0, 0, 0, .2);
  backdrop-filter: blur(8px);
}
.cb-kpi-label { font-size: 13px; font-weight: 700; letter-spacing: .12em; text-transform: uppercase; color: var(--ink-4); margin-bottom: 8px; }
.cb-kpi-value {
  font: 200 36px var(--font);
  letter-spacing: -.04em;
  font-variant-numeric: tabular-nums;
  color: var(--ink);
  text-shadow: 0 2px 20px rgba(0, 0, 0, .5), 0 0 40px var(--gold-glow);
  margin-bottom: 6px;
}
.cb-kpi-foot { font-size: 11px; color: var(--ink-3); }
.cb-kpi.cb-kpi-good .cb-kpi-value { color: var(--green); text-shadow: 0 0 20px var(--green-glow); }
.cb-kpi.cb-kpi-bad  .cb-kpi-value { color: var(--red);   text-shadow: 0 0 20px var(--red-glow); }
.cb-kpi.cb-kpi-warn .cb-kpi-value { color: var(--amber); text-shadow: 0 0 20px var(--amber-glow); }
html.light .cb-kpi-value { text-shadow: 0 2px 6px rgba(0, 0, 0, .06); }
html.light .cb-kpi {
  background: linear-gradient(180deg, rgba(0, 0, 0, .02) 0%, rgba(0, 0, 0, .005) 100%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .05);
}

/* ──────────────────────────────────────────────────────────────────────
 * Period grid — Jan-Dec status table for the current fiscal year
 * ────────────────────────────────────────────────────────────────────── */
.cb-card {
  margin: 16px 0;
  padding: 24px;
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, rgba(255, 255, 255, .03) 0%, rgba(255, 255, 255, .015) 100%);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .05), 0 4px 16px rgba(0, 0, 0, .3);
  backdrop-filter: blur(8px);
}
html.light .cb-card {
  background: linear-gradient(180deg, rgba(0, 0, 0, .02) 0%, rgba(0, 0, 0, .005) 100%);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06), 0 2px 8px rgba(0, 0, 0, .05);
}
.cb-card-head {
  display: flex; align-items: baseline; justify-content: space-between;
  gap: 16px; margin-bottom: 12px; flex-wrap: wrap;
}
.cb-card-title { font: 600 16px var(--font); letter-spacing: -.015em; color: var(--ink); }
.cb-card-meta { font-size: 11px; color: var(--ink-3); letter-spacing: .04em; text-transform: uppercase; }

.cb-period-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(180px, 1fr));
  gap: 12px;
  margin-top: 12px;
}
.cb-period-card {
  padding: 16px 18px;
  border-radius: var(--r);
  background: rgba(255, 255, 255, .03);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06);
  display: flex; flex-direction: column; gap: 8px;
}
html.light .cb-period-card { background: rgba(0, 0, 0, .03); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .07); }
.cb-period-card.is-closed { background: linear-gradient(180deg, rgba(74,222,128,.06), rgba(74,222,128,.02)); box-shadow: inset 0 0 0 1px rgba(74,222,128,.18); }
.cb-period-card.is-current { box-shadow: inset 0 0 0 2px rgba(200,160,76,.25); background: rgba(200,160,76,.04); }
.cb-period-month { font: 700 13px var(--font); color: var(--ink); letter-spacing: .04em; text-transform: uppercase; }
.cb-period-meta { font-size: 12px; color: var(--ink-3); }
.cb-period-status {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 3px 10px;
  font: 600 11px var(--font);
  border-radius: 9999px;
}
.cb-period-status::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }
.cb-period-status.is-open { color: var(--ink-3); background: rgba(154, 154, 170, .08); box-shadow: inset 0 0 0 1px rgba(154, 154, 170, .14); }
.cb-period-status.is-soft-closed { color: var(--amber); background: var(--amber-glow); }
.cb-period-status.is-hard-closed { color: var(--green); background: var(--green-glow); }

.cb-period-actions {
  display: flex; gap: 6px; flex-wrap: wrap;
  margin-top: 4px;
}
.cb-period-action {
  flex: 1 1 auto;
  min-height: 36px;
  padding: 6px 10px;
  font: 600 11.5px var(--font);
  background: rgba(255, 255, 255, .04);
  color: var(--ink-2);
  border: none;
  border-radius: var(--r-sm);
  cursor: pointer;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .06);
  transition: all .2s var(--spring);
}
.cb-period-action:hover { color: var(--gold); background: var(--gold-glow); box-shadow: inset 0 0 0 1px var(--gold-glow-ring); }

/* ──────────────────────────────────────────────────────────────────────
 * Review feed (right column on detail; or own card on list)
 * ────────────────────────────────────────────────────────────────────── */
.cb-feed {
  display: flex; flex-direction: column; gap: 8px;
  margin-top: 12px;
}
.cb-feed-item {
  padding: 12px 14px;
  background: rgba(255, 255, 255, .03);
  border-radius: var(--r-sm);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .05);
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
}
html.light .cb-feed-item { background: rgba(0, 0, 0, .03); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06); }
.cb-feed-icon {
  width: 32px; height: 32px;
  border-radius: 50%;
  display: grid; place-items: center;
  font: 700 11px var(--font);
}
.cb-feed-icon.is-reclass { color: var(--blue); background: var(--blue-glow); }
.cb-feed-icon.is-writeoff { color: var(--amber); background: var(--amber-glow); }
.cb-feed-text { font-size: 13px; color: var(--ink); }
.cb-feed-text strong { color: var(--ink); }
.cb-feed-meta { font-size: 11px; color: var(--ink-3); white-space: nowrap; }

/* Empty / loading / error */
.cb-empty {
  margin: 60px auto;
  max-width: 520px;
  padding: 40px 30px;
  text-align: center;
  border-radius: var(--r-lg);
  background: linear-gradient(180deg, rgba(255, 255, 255, .03), rgba(255, 255, 255, .01));
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .05);
}
html.light .cb-empty { background: linear-gradient(180deg, rgba(0, 0, 0, .02), rgba(0, 0, 0, .005)); box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06); }
.cb-empty-title { font: 600 16px var(--font); margin-bottom: 8px; color: var(--ink); }
.cb-empty-desc { font-size: 13px; color: var(--ink-2); margin-bottom: 16px; }

.cb-skel-strip {
  height: 100px;
  margin: 16px 0;
  border-radius: var(--r-lg);
  background:
    linear-gradient(90deg, transparent 0%, rgba(255, 255, 255, .04) 50%, transparent 100%),
    rgba(255, 255, 255, .02);
  background-size: 200% 100%;
  animation: cb-shimmer 1.4s ease-in-out infinite;
}
@keyframes cb-shimmer { 0% { background-position: 200% 0; } 100% { background-position: -200% 0; } }

.cb-error-card {
  margin: 20px 0; padding: 20px 24px;
  border-radius: var(--r-lg);
  background: var(--red-glow);
  box-shadow: inset 0 0 0 1px rgba(248, 113, 113, .18);
  color: var(--ink);
}
.cb-error-title { font: 600 14px var(--font); color: var(--red); margin-bottom: 6px; }
.cb-error-desc { font-size: 12px; color: var(--ink-2); font-family: ui-monospace, monospace; word-break: break-word; }

/* ──────────────────────────────────────────────────────────────────────
 * Form helpers (used inside global modals)
 * ────────────────────────────────────────────────────────────────────── */
.cb-form { display: flex; flex-direction: column; gap: 16px; }
.cb-form-row { display: flex; flex-direction: column; gap: 6px; }
.cb-form-row > label {
  font-size: 11px; font-weight: 700; letter-spacing: .08em;
  text-transform: uppercase; color: var(--ink-3);
}
.cb-form-grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
@media (max-width: 600px) { .cb-form-grid-2 { grid-template-columns: 1fr; } }

/* `shell-override-v2.css:540-547` applies `.page input { box-shadow:
 * ... !important }` and `.page input:focus { box-shadow: ... !important }`
 * which clobbers our :focus styling. Use `!important` on hover/focus/
 * is-saving/is-saved/is-error so cb-input wins the cascade. (Lesson
 * from Tracker #20 phase20_c hotfix.) */
.cb-input,
select.cb-input,
textarea.cb-input {
  padding: 10px 14px;
  font: 500 14px var(--font);
  background: rgba(255, 255, 255, .03);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08);
  border: none;
  border-radius: var(--r-sm);
  color: var(--ink);
  transition: all .2s var(--spring);
  width: 100%;
  appearance: none;
  -webkit-appearance: none;
  box-sizing: border-box;
}
.cb-input:hover,
select.cb-input:hover,
textarea.cb-input:hover {
  background: rgba(255, 255, 255, .05) !important;
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .12) !important;
}
.cb-input:focus,
select.cb-input:focus,
textarea.cb-input:focus {
  outline: none !important;
  background: rgba(200, 160, 76, .08) !important;
  box-shadow: 0 0 0 2px var(--gold), inset 0 0 0 1px var(--gold) !important;
}
html.light .cb-input,
html.light select.cb-input,
html.light textarea.cb-input {
  background: rgba(0, 0, 0, .025);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08);
  color: var(--ink);
}
html.light .cb-input:focus,
html.light select.cb-input:focus,
html.light textarea.cb-input:focus {
  background: rgba(150, 117, 10, .06) !important;
  box-shadow: 0 0 0 2px #966D0A, inset 0 0 0 1px #966D0A !important;
}
.cb-input.is-saving { background: rgba(96, 165, 250, .08) !important; }
.cb-input.is-error { background: rgba(248, 113, 113, .10) !important; box-shadow: inset 0 0 0 2px rgba(248, 113, 113, .35) !important; }
.cb-input.is-saved { background: rgba(74, 222, 128, .12) !important; box-shadow: inset 0 0 0 1px rgba(74, 222, 128, .35) !important; transition: background .3s, box-shadow .3s; }
textarea.cb-input { min-height: 80px; resize: vertical; }
select.cb-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%239898A8' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M3 4.5l3 3 3-3'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 12px center;
  padding-right: 32px;
  color-scheme: dark;
}
html.light select.cb-input {
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='none' stroke='%23A8A29E' stroke-width='2' stroke-linecap='round'%3E%3Cpath d='M3 4.5l3 3 3-3'/%3E%3C/svg%3E");
  color-scheme: light;
}

.cb-hint { font-size: 11px; color: var(--ink-3); line-height: 1.5; }
.cb-hint strong { color: var(--ink); font-weight: 700; }

/* Reclassify line editor table inside modal */
.cb-reclass-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  margin: 8px 0;
}
.cb-reclass-table th {
  font: 700 10px var(--font);
  letter-spacing: .06em;
  text-transform: uppercase;
  color: var(--ink-3);
  text-align: left;
  padding: 8px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, .06);
}
.cb-reclass-table td {
  padding: 8px 6px;
  border-bottom: 1px solid rgba(255, 255, 255, .03);
}
html.light .cb-reclass-table td { border-bottom: 1px solid rgba(0, 0, 0, .04); }
html.light .cb-reclass-table th { border-bottom: 1px solid rgba(0, 0, 0, .06); }
.cb-reclass-table .cb-reclass-num { width: 110px; }
.cb-reclass-table .cb-input { padding: 6px 10px; }

.cb-balance-pill {
  display: inline-flex; align-items: center; gap: 5px;
  padding: 4px 10px;
  font: 700 11px var(--font);
  border-radius: 9999px;
  margin-top: 8px;
}
.cb-balance-pill.is-balanced { color: var(--green); background: var(--green-glow); }
.cb-balance-pill.is-unbalanced { color: var(--red); background: var(--red-glow); }
.cb-balance-pill::before { content: ""; width: 6px; height: 6px; border-radius: 50%; background: currentColor; }

/* ──────────────────────────────────────────────────────────────────────
 * Modal — page-scoped tweaks ONLY. Heavy lifting is the global
 * .modal-overlay / .rgb-orb / .modal-panel system from ui-components.css.
 * ────────────────────────────────────────────────────────────────────── */
.cb-modal.modal-overlay .modal-panel { max-width: 720px; }
.cb-modal.modal-overlay .modal-panel.cb-modal-md { max-width: 560px; }
.cb-modal.modal-overlay .modal-panel.cb-modal-sm { max-width: 440px; }
.cb-modal.modal-overlay .modal-close {
  width: 44px; height: 44px;
  min-width: 44px; min-height: 44px;
  font-size: 18px;
}

/* .ui-dropdown scoped — overrides /app/ui-components.css :466
 * `.ui-dropdown { width: 100% }` (lesson from Tracker #10 phase10_g). */
#close-books-host .ui-dropdown,
.cb-modal .ui-dropdown {
  position: relative;
  display: inline-block;
  width: auto;
}
#close-books-host .ui-dropdown-trigger,
.cb-modal .ui-dropdown-trigger {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 10px 14px; min-height: 44px;
  background: linear-gradient(180deg, rgba(255, 255, 255, .05), rgba(255, 255, 255, .02));
  color: var(--ink);
  font: 500 13px var(--font);
  border: none; border-radius: var(--r-sm);
  cursor: pointer;
  transition: all .22s var(--spring);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .07), 0 2px 12px rgba(0, 0, 0, .20);
}
html.light #close-books-host .ui-dropdown-trigger,
html.light .cb-modal .ui-dropdown-trigger {
  background: linear-gradient(180deg, #FFFFFF, #FAFAF8);
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .08), 0 2px 12px rgba(0, 0, 0, .04);
}
#close-books-host .ui-dropdown-menu,
.cb-modal .ui-dropdown-menu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  min-width: 100%;
  background: var(--elevated);
  backdrop-filter: blur(20px);
  -webkit-backdrop-filter: blur(20px);
  box-shadow: inset 0 0 0 1px rgba(255, 255, 255, .08), 0 8px 32px rgba(0, 0, 0, .50);
  border-radius: var(--r);
  padding: 6px;
  max-height: 320px;
  overflow-y: auto;
  opacity: 0;
  transform: translateY(-8px) scale(.98);
  pointer-events: none;
  transition: all .22s var(--spring);
  z-index: 1100;
}
html.light #close-books-host .ui-dropdown-menu,
html.light .cb-modal .ui-dropdown-menu {
  background: #FFFFFF;
  box-shadow: inset 0 0 0 1px rgba(0, 0, 0, .06), 0 8px 32px rgba(0, 0, 0, .10);
}
#close-books-host .ui-dropdown.open .ui-dropdown-menu,
.cb-modal .ui-dropdown.open .ui-dropdown-menu {
  opacity: 1;
  transform: translateY(0) scale(1);
  pointer-events: auto;
}
#close-books-host .ui-dropdown-item,
.cb-modal .ui-dropdown-item {
  padding: 8px 12px 8px 28px;
  border-radius: 8px;
  font: 400 13px var(--font);
  color: var(--ink);
  cursor: pointer;
  transition: background .15s ease;
  position: relative;
}
#close-books-host .ui-dropdown-item:hover,
.cb-modal .ui-dropdown-item:hover { background: rgba(255, 255, 255, .05); }
html.light #close-books-host .ui-dropdown-item:hover,
html.light .cb-modal .ui-dropdown-item:hover { background: rgba(0, 0, 0, .04); }
#close-books-host .ui-dropdown-item.selected::before,
.cb-modal .ui-dropdown-item.selected::before {
  content: ""; position: absolute; left: 12px; top: 50%; transform: translateY(-50%);
  width: 6px; height: 6px; border-radius: 50%;
  background: var(--gold);
  box-shadow: 0 0 8px rgba(200, 160, 76, .5);
}

/* Responsive */
@media (max-width: 768px) {
  .cb-page { padding: 16px; }
  .cb-period-grid { grid-template-columns: repeat(2, 1fr); }
  .cb-feed-item { grid-template-columns: auto 1fr; }
  .cb-feed-meta { grid-column: 2; font-size: 10px; }
}
@media (max-width: 480px) {
  .cb-section-head { flex-direction: column; align-items: stretch; }
  .cb-toolbar { flex-direction: column; align-items: stretch; }
  .cb-kpi-grid { grid-template-columns: 1fr; }
  .cb-period-grid { grid-template-columns: 1fr; }
}
