/* Tally — ledger-style eBay profit tracker */

:root {
  --paper: #F3F5F4;
  --card: #FFFFFF;
  --ink: #17241F;
  --teal: #1D4E45;
  --moss: #2F7D5C;
  --rust: #B54B3B;
  --gold: #B9852F;
  --muted: #5C6B64;
  --line: #D8DED9;
  --focus: #1D4E45;
  --sidebar-w: 220px;
  --radius: 6px;
}

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

html, body {
  margin: 0;
  padding: 0;
  background: var(--paper);
  color: var(--ink);
  font-family: 'Inter', system-ui, sans-serif;
  font-size: 15px;
  line-height: 1.5;
  min-height: 100%;
}

h1, h2, h3, h4, .serif {
  font-family: 'Source Serif 4', Georgia, serif;
  font-weight: 600;
  letter-spacing: -0.01em;
  margin: 0 0 0.4em;
}

.mono, .num, table td.num, table th.num {
  font-family: 'IBM Plex Mono', ui-monospace, monospace;
  font-variant-numeric: tabular-nums;
  font-feature-settings: "tnum";
}

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

/* Focus states — visible everywhere */
:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}
button:focus-visible,
a.btn:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 2px solid var(--focus);
  outline-offset: 2px;
}

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

.sidebar {
  width: var(--sidebar-w);
  background: var(--ink);
  color: #E8EEEA;
  flex-shrink: 0;
  display: flex;
  flex-direction: column;
  padding: 1.5rem 0;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  padding: 0 1.25rem 1.5rem;
  border-bottom: 1px solid rgba(255,255,255,0.08);
  margin-bottom: 1rem;
}
.sidebar-brand .logo {
  font-family: 'Source Serif 4', Georgia, serif;
  font-size: 1.5rem;
  color: #fff;
  letter-spacing: -0.02em;
}
.sidebar-brand .tag {
  font-size: 0.72rem;
  color: rgba(255,255,255,0.45);
  text-transform: uppercase;
  letter-spacing: 0.08em;
  margin-top: 0.15rem;
}

.sidebar nav {
  display: flex;
  flex-direction: column;
  gap: 0.15rem;
  padding: 0 0.75rem;
  flex: 1;
}

.sidebar nav a {
  display: block;
  padding: 0.55rem 0.75rem;
  border-radius: var(--radius);
  color: rgba(255,255,255,0.72);
  text-decoration: none;
  font-size: 0.92rem;
  transition: background 0.12s, color 0.12s;
}
.sidebar nav a:hover {
  background: rgba(255,255,255,0.06);
  color: #fff;
  text-decoration: none;
}
.sidebar nav a.active {
  background: var(--teal);
  color: #fff;
}

.sidebar-foot {
  padding: 1rem 1.25rem 0;
  border-top: 1px solid rgba(255,255,255,0.08);
  font-size: 0.8rem;
  color: rgba(255,255,255,0.45);
}
.sidebar-foot form { margin-top: 0.5rem; }
.sidebar-foot button {
  background: none;
  border: none;
  color: rgba(255,255,255,0.7);
  cursor: pointer;
  font: inherit;
  padding: 0;
}
.sidebar-foot button:hover { color: #fff; text-decoration: underline; }

.main {
  flex: 1;
  min-width: 0;
  padding: 1.75rem 2rem 3rem;
  display: flex;
  flex-direction: column;
}

.site-footer {
  margin-top: auto;
  padding-top: 2.5rem;
  text-align: center;
  font-size: 0.82rem;
  color: var(--muted);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 0.3rem;
}
.site-footer--auth {
  margin-top: 1.5rem;
  padding-top: 1.25rem;
  border-top: 1px solid var(--line);
}
.heart-icon {
  display: inline-block;
  vertical-align: middle;
  color: var(--rust);
  flex-shrink: 0;
}

.page-header {
  display: flex;
  flex-wrap: wrap;
  align-items: flex-start;
  justify-content: space-between;
  gap: 1rem;
  margin-bottom: 1.5rem;
}
.page-header h1 {
  font-size: 1.75rem;
  margin: 0;
}
.page-header .sub {
  color: var(--muted);
  font-size: 0.9rem;
  margin-top: 0.2rem;
}

/* Cards */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 1.25rem;
}
.card + .card { margin-top: 1rem; }

.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.grid-5 {
  display: grid;
  grid-template-columns: repeat(5, 1fr);
  gap: 1rem;
  margin-bottom: 1.25rem;
}
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 1rem;
}
.stat-card .label {
  font-size: 0.78rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
  color: var(--muted);
  margin-bottom: 0.35rem;
}
.stat-card .value {
  font-size: 1.55rem;
  font-family: 'IBM Plex Mono', monospace;
  font-variant-numeric: tabular-nums;
}
.stat-card .value.positive { color: var(--moss); }
.stat-card .value.negative { color: var(--rust); }
.stat-card .stat-meta {
  margin-top: 0.3rem;
  font-size: 0.75rem;
  color: var(--muted);
}

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 0.4rem;
  padding: 0.5rem 1rem;
  border-radius: var(--radius);
  border: 1px solid transparent;
  font-family: inherit;
  font-size: 0.9rem;
  cursor: pointer;
  text-decoration: none;
  line-height: 1.3;
  background: var(--teal);
  color: #fff;
}
.btn:hover { filter: brightness(1.08); text-decoration: none; color: #fff; }
.btn:disabled { opacity: 0.5; cursor: not-allowed; }
.btn-secondary {
  background: #fff;
  color: var(--ink);
  border-color: var(--line);
}
.btn-secondary:hover { background: var(--paper); color: var(--ink); }
.btn-danger {
  background: var(--rust);
  color: #fff;
}
.btn-sm { padding: 0.3rem 0.65rem; font-size: 0.82rem; }
.link-btn {
  background: none;
  border: none;
  padding: 0;
  margin: 0;
  font: inherit;
  font-size: 0.75rem;
  color: var(--teal);
  text-decoration: underline;
  cursor: pointer;
}
.link-btn:hover { color: var(--ink); }
.link-btn:focus-visible {
  outline: 2px solid var(--teal);
  outline-offset: 2px;
}
[x-cloak] { display: none !important; }

/* Forms */
.form-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(140px, 1fr));
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
label {
  display: block;
  font-size: 0.8rem;
  color: var(--muted);
  margin-bottom: 0.25rem;
}
input[type="text"],
input[type="number"],
input[type="email"],
input[type="password"],
input[type="date"],
input[type="month"],
input[type="search"],
select,
textarea {
  width: 100%;
  padding: 0.5rem 0.65rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  font-family: inherit;
  font-size: 0.92rem;
  background: #fff;
  color: var(--ink);
}
input.mono, .cpu-display {
  font-family: 'IBM Plex Mono', monospace;
  font-variant-numeric: tabular-nums;
}

/* Locked / non-editable fields (qty, cost, remaining, etc.) */
input:disabled,
input[readonly].input-locked,
.input-locked {
  background: #E8EBEA !important;
  color: #6B756F !important;
  border-color: #C5CBC8 !important;
  cursor: not-allowed;
  opacity: 1; /* override browser grey that can look broken */
  -webkit-text-fill-color: #6B756F;
}
label.locked-label {
  color: #8A938E;
}
label.locked-label::after {
  content: ' · locked';
  font-weight: 400;
  font-size: 0.72rem;
  letter-spacing: 0.01em;
}

.hint {
  font-size: 0.85rem;
  color: var(--muted);
  margin-top: 0.35rem;
}
.restock-note {
  background: #EEF6F1;
  border: 1px solid #C5DFD0;
  color: var(--moss);
  padding: 0.6rem 0.8rem;
  border-radius: var(--radius);
  font-size: 0.88rem;
  margin: 0.5rem 0;
}
.restock-note[hidden] { display: none; }

/* Tables */
.table-wrap { overflow-x: auto; }
table.data {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
}
table.data th {
  text-align: left;
  font-weight: 500;
  color: var(--muted);
  font-size: 0.75rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  padding: 0.55rem 0.65rem;
  border-bottom: 1px solid var(--line);
  white-space: nowrap;
}
table.data td {
  padding: 0.65rem;
  border-bottom: 1px solid var(--line);
  vertical-align: middle;
}
table.data tr:last-child td { border-bottom: none; }
table.data th.num, table.data td.num { text-align: right; }
table.data tbody tr:hover { background: #FAFBFA; }

/* Badges */
.badge {
  display: inline-block;
  padding: 0.15rem 0.5rem;
  border-radius: 999px;
  font-size: 0.72rem;
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.04em;
}
.badge-paid { background: #E8F3EC; color: var(--moss); }
.badge-refunded { background: #F8EBE8; color: var(--rust); }
.badge-partial { background: #F8F1E3; color: var(--gold); }
.badge-unmatched { background: #EEF0EF; color: var(--muted); }
.badge-low { background: #F8F1E3; color: var(--gold); }
.badge-ok { background: #E8F3EC; color: var(--moss); }

/* Alerts */
.alert {
  padding: 0.75rem 1rem;
  border-radius: var(--radius);
  margin-bottom: 1rem;
  font-size: 0.9rem;
}
.alert-success { background: #E8F3EC; color: var(--moss); border: 1px solid #C5DFD0; }
.alert-error { background: #F8EBE8; color: var(--rust); border: 1px solid #E8C8C2; }

/* Receipt tape (signature Overview element) */
.receipt-tape {
  background: #FFFEF8;
  border: 1px solid #E5E0D0;
  padding: 1.25rem 1.25rem 1.75rem;
  position: relative;
  max-width: 320px;
  box-shadow: none;
}
.receipt-tape::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -10px;
  height: 10px;
  background:
    linear-gradient(135deg, #FFFEF8 5px, transparent 0) 0 0 / 10px 10px,
    linear-gradient(45deg, #FFFEF8 5px, transparent 0) 0 0 / 10px 10px;
  background-color: transparent;
  /* zigzag torn edge using clip on a pseudo bar */
  background-image: none;
  /* CSS zigzag via polygon clip on a solid strip */
}
.receipt-tape .torn {
  position: absolute;
  left: -1px;
  right: -1px;
  bottom: -12px;
  height: 12px;
  background: #FFFEF8;
  border-left: 1px solid #E5E0D0;
  border-right: 1px solid #E5E0D0;
  clip-path: polygon(
    0 0, 100% 0,
    100% 0,
    97% 100%, 94% 0, 91% 100%, 88% 0, 85% 100%, 82% 0, 79% 100%,
    76% 0, 73% 100%, 70% 0, 67% 100%, 64% 0, 61% 100%, 58% 0, 55% 100%,
    52% 0, 49% 100%, 46% 0, 43% 100%, 40% 0, 37% 100%, 34% 0, 31% 100%,
    28% 0, 25% 100%, 22% 0, 19% 100%, 16% 0, 13% 100%, 10% 0, 7% 100%,
    4% 0, 1% 100%, 0 0
  );
  filter: drop-shadow(0 1px 0 #E5E0D0);
}
.receipt-tape h3 {
  font-size: 0.95rem;
  margin-bottom: 0.15rem;
}
.receipt-tape .receipt-meta {
  font-size: 0.75rem;
  color: var(--muted);
  margin-bottom: 1rem;
  text-transform: uppercase;
  letter-spacing: 0.06em;
}
.sparkline {
  display: flex;
  align-items: flex-end;
  gap: 6px;
  height: 72px;
  padding-bottom: 1.4rem;
  position: relative;
}
.sparkline .bar-wrap {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  height: 100%;
  justify-content: flex-end;
  position: relative;
}
.sparkline .bar {
  width: 100%;
  max-width: 28px;
  background: #C5D4CE;
  border-radius: 2px 2px 0 0;
  min-height: 2px;
  transition: height 0.2s;
}
.sparkline .bar.today {
  background: var(--teal);
}
.sparkline .bar.neg {
  background: #E0B8B2;
}
.sparkline .bar.today.neg {
  background: var(--rust);
}
.sparkline .day-label {
  position: absolute;
  bottom: -1.25rem;
  font-size: 0.65rem;
  color: var(--muted);
  font-family: 'IBM Plex Mono', monospace;
}

/* Activity list */
.activity-list { list-style: none; margin: 0; padding: 0; }
.activity-list li {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.7rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.9rem;
}
.activity-list li:last-child { border-bottom: none; }
.activity-list .meta { color: var(--muted); font-size: 0.8rem; }
.activity-list .amt { font-family: 'IBM Plex Mono', monospace; font-variant-numeric: tabular-nums; white-space: nowrap; }
.activity-list .amt.pos { color: var(--moss); }
.activity-list .amt.neg { color: var(--rust); }

/* Empty state */
.empty {
  text-align: center;
  padding: 2.5rem 1rem;
  color: var(--muted);
}
.empty .serif { color: var(--ink); margin-bottom: 0.35rem; }

/* Filters bar */
.filters {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  align-items: flex-end;
  margin-bottom: 1rem;
}
.filters .field { min-width: 130px; }

/* Pagination */
.pagination {
  display: flex;
  gap: 0.35rem;
  list-style: none;
  padding: 1rem 0 0;
  margin: 0;
  flex-wrap: wrap;
}
.pagination li a,
.pagination li span {
  display: inline-block;
  padding: 0.3rem 0.6rem;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  color: var(--ink);
  font-size: 0.85rem;
  text-decoration: none;
}
.pagination li.active span {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}
.pagination li.disabled span { opacity: 0.4; }

/* Auth pages */
.auth-wrap {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem;
  background: var(--paper);
}
.auth-card {
  width: 100%;
  max-width: 400px;
  background: #fff;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 2rem;
}
.auth-card h1 {
  font-size: 1.6rem;
  margin-bottom: 0.25rem;
}
.auth-card .sub { color: var(--muted); margin-bottom: 1.5rem; font-size: 0.9rem; }
.auth-card .field { margin-bottom: 1rem; }
.auth-card .btn { width: 100%; justify-content: center; margin-top: 0.5rem; }
.auth-card .error { color: var(--rust); font-size: 0.85rem; margin-top: 0.25rem; }

/* Chart */
.chart-box {
  width: 100%;
  height: 260px;
  position: relative;
}
.chart-box canvas { width: 100% !important; height: 100% !important; }

/* Settings blocks */
.settings-row {
  display: flex;
  justify-content: space-between;
  gap: 1rem;
  padding: 0.75rem 0;
  border-bottom: 1px solid var(--line);
  font-size: 0.92rem;
}
.settings-row:last-child { border-bottom: none; }
.settings-row .k { color: var(--muted); }
.readonly-callout {
  background: #EEF4F2;
  border: 1px solid #C5D9D2;
  border-radius: var(--radius);
  padding: 0.85rem 1rem;
  font-size: 0.9rem;
  margin: 1rem 0;
  color: var(--teal);
}

/* Shipping select counter */
.select-bar {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 0.75rem;
  margin-bottom: 0.75rem;
}
.select-bar .count {
  font-family: 'IBM Plex Mono', monospace;
  font-size: 0.9rem;
  color: var(--muted);
}

/* Responsive: sidebar → horizontal bar */
@media (max-width: 1100px) {
  .grid-5 { grid-template-columns: repeat(3, 1fr); }
}
@media (max-width: 900px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
  .grid-5 { grid-template-columns: repeat(2, 1fr); }
  .grid-2 { grid-template-columns: 1fr; }
  .main { padding: 1.25rem 1rem 2rem; }
}

@media (max-width: 720px) {
  .app-shell { flex-direction: column; }
  .sidebar {
    width: 100%;
    height: auto;
    position: relative;
    padding: 0.75rem 0;
  }
  .sidebar-brand {
    padding: 0.5rem 1rem;
    border-bottom: none;
    margin-bottom: 0;
    display: flex;
    align-items: baseline;
    gap: 0.75rem;
  }
  .sidebar nav {
    flex-direction: row;
    overflow-x: auto;
    padding: 0.25rem 0.75rem 0.75rem;
    gap: 0.25rem;
    -webkit-overflow-scrolling: touch;
  }
  .sidebar nav a {
    white-space: nowrap;
    flex-shrink: 0;
  }
  .sidebar-foot { display: none; }
  .grid-4 { grid-template-columns: 1fr 1fr; }
  .grid-5 { grid-template-columns: 1fr 1fr; }
}
