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

:root {
  --bg: #f5f5f7;
  --card: #fff;
  --border: #e5e7eb;
  --text: #111827;
  --muted: #6b7280;
  --blue: #2563eb;
  --green: #16a34a;
  --red: #dc2626;
  --amber: #d97706;
  --radius: 12px;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.04);
}

html, body {
  height: 100%;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

#app {
  display: flex;
  flex-direction: column;
  height: 100%;
  max-width: 640px;
  margin: 0 auto;
  position: relative;
  overflow: hidden;
}

/* ── Views ── */
.view {
  display: none;
  flex-direction: column;
  flex: 1;
  overflow: hidden;
  min-height: 0;
}
.view.active { display: flex; }

/* ── Header ── */
header {
  background: #fff;
  border-bottom: 1px solid var(--border);
  padding: 12px 16px 0;
  flex-shrink: 0;
}
header h1 {
  font-size: 22px;
  font-weight: 700;
  padding-bottom: 12px;
}

/* ── Sort tabs ── */
.sort-tabs {
  display: flex;
  gap: 4px;
}
.sort-btn {
  flex: 1;
  padding: 8px 0;
  border: none;
  background: none;
  font-size: 14px;
  font-weight: 500;
  color: var(--muted);
  cursor: pointer;
  border-bottom: 3px solid transparent;
  transition: color .15s, border-color .15s;
}
.sort-btn.active {
  color: var(--blue);
  border-bottom-color: var(--blue);
}

/* ── List ── */
.list {
  flex: 1;
  overflow-y: auto;
  padding: 12px 12px 8px;
  -webkit-overflow-scrolling: touch;
}

/* ── Base card ── */
.card {
  background: var(--card);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 14px 16px;
  margin-bottom: 10px;
  cursor: pointer;
  transition: transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.card:active { transform: scale(0.98); }

/* ── Bundle card ── */
.bundle-top {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 10px;
  margin-bottom: 6px;
}
.bundle-case-block {
  flex: 1;
  min-width: 0;
}
.bundle-case-name {
  display: block;
  font-size: 17px;
  font-weight: 700;
  color: var(--text);
  line-height: 1.3;
  margin-bottom: 2px;
}
.bundle-court {
  display: block;
  font-size: 12px;
  color: var(--muted);
  font-weight: 400;
}
.bundle-filings {
  font-size: 13px;
  color: var(--muted);
  margin-bottom: 8px;
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}
.bundle-filings .more {
  color: var(--blue);
  font-weight: 500;
}
.bundle-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 6px;
}
.bundle-meta {
  display: flex;
  align-items: center;
  gap: 8px;
}
/* keep .case-name for settled cards */
.case-name {
  font-size: 15px;
  font-weight: 600;
  color: var(--text);
  flex: 1;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}
.filing-count-chip {
  font-size: 11px;
  font-weight: 600;
  color: var(--blue);
  background: #eff6ff;
  padding: 2px 8px;
  border-radius: 20px;
}
.type-chips {
  display: flex;
  flex-wrap: wrap;
  gap: 4px;
}
.type-chip {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--blue);
  background: #eff6ff;
  padding: 2px 7px;
  border-radius: 20px;
}
.recency-badge {
  font-size: 11px;
  font-weight: 600;
  padding: 2px 8px;
  border-radius: 20px;
}
.rec-hot    { background: #fee2e2; color: #991b1b; }
.rec-recent { background: #fef3c7; color: #92400e; }
.rec-today  { background: #dcfce7; color: #166534; }
.rec-old    { background: #f3f4f6; color: var(--muted); }

.deadline {
  font-size: 12px;
  color: var(--amber);
  font-weight: 500;
}
.fdate {
  font-size: 12px;
  color: var(--muted);
}

/* ── Priority badges ── */
.priority {
  font-size: 11px;
  font-weight: 700;
  padding: 2px 7px;
  border-radius: 20px;
}
.pri-high { background: #fee2e2; color: #991b1b; }
.pri-med  { background: #fef3c7; color: #92400e; }
.pri-low  { background: #f3f4f6; color: #374151; }

/* ── Settled card ── */
.settled-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 4px;
}
.settled-footer {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-top: 8px;
}
.card-headline {
  font-size: 14px;
  color: var(--text);
  line-height: 1.4;
  overflow: hidden;
  display: -webkit-box;
  -webkit-line-clamp: 2;
  -webkit-box-orient: vertical;
}

/* ── Status badges ── */
.status-badge {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  padding: 2px 8px;
  border-radius: 20px;
  white-space: nowrap;
}
.status-approved  { background: #dcfce7; color: #166534; }
.status-rejected  { background: #fee2e2; color: #991b1b; }
.status-deferred  { background: #fef9c3; color: #713f12; }
.status-dismissed { background: #f3f4f6; color: var(--muted); }

/* ── Bottom tabs ── */
.tabs {
  display: flex;
  background: #fff;
  border-top: 1px solid var(--border);
  flex-shrink: 0;
  padding-bottom: env(safe-area-inset-bottom);
}
.tab-btn {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 0;
  border: none;
  background: none;
  font-size: 11px;
  color: var(--muted);
  cursor: pointer;
  gap: 2px;
  transition: color .15s;
}
.tab-btn.active { color: var(--blue); }
.tab-icon { font-size: 20px; }

/* ── Detail view ── */
.detail-header {
  flex-direction: row !important;
  align-items: center;
  gap: 10px;
  padding: 12px 16px !important;
  padding-bottom: 12px !important;
}
.back-btn {
  background: none;
  border: none;
  font-size: 17px;
  color: var(--blue);
  cursor: pointer;
  padding: 4px 0;
  flex-shrink: 0;
}
.detail-title {
  display: flex;
  align-items: center;
  gap: 8px;
  flex: 1;
  min-width: 0;
  flex-wrap: wrap;
}
.case-name-sm {
  font-size: 14px;
  font-weight: 600;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.detail-content {
  flex: 1;
  overflow-y: auto;
  -webkit-overflow-scrolling: touch;
  min-height: 0;
}
.detail-content h2 {
  font-size: 19px;
  font-weight: 700;
  line-height: 1.3;
  margin-bottom: 4px;
  padding: 16px 16px 0;
}
.action-id-detail {
  font-size: 11px;
  color: var(--muted);
  font-family: monospace;
  padding: 0 16px 12px;
}

/* ── Filing list (bundle detail) ── */
.filing-list {
  padding: 8px 0;
}
.filing-item {
  border-bottom: 1px solid var(--border);
}
.filing-item:last-child { border-bottom: none; }

.filing-row {
  display: flex;
  align-items: flex-start;
  padding: 12px 16px;
  gap: 10px;
  cursor: pointer;
  -webkit-tap-highlight-color: transparent;
}
.filing-row:active { background: #f9fafb; }

.filing-check-wrap {
  flex-shrink: 0;
  padding-top: 2px;
}
.filing-check {
  width: 18px;
  height: 18px;
  accent-color: var(--blue);
  cursor: pointer;
}

.filing-info {
  flex: 1;
  min-width: 0;
  cursor: pointer;
}
.filing-headline {
  font-size: 14px;
  font-weight: 500;
  line-height: 1.4;
  display: block;
  margin-bottom: 5px;
}
.filing-chips {
  display: flex;
  flex-wrap: wrap;
  align-items: center;
  gap: 5px;
}

.expand-btn {
  flex-shrink: 0;
  background: none;
  border: none;
  font-size: 18px;
  color: var(--muted);
  cursor: pointer;
  padding: 0 2px;
  line-height: 1;
  align-self: center;
}

/* ── Expanded filing body ── */
.filing-expanded {
  padding: 0 16px 16px 44px;
}
.filing-body { }
.filing-body-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.filing-body h4, .att-section h4 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: 6px;
}
.filing-body p {
  font-size: 14px;
  line-height: 1.6;
}
.att-section {
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}

/* ── Markdown ── */
.markdown { font-size: 13px; line-height: 1.7; }
.markdown h1 { font-size: 15px; font-weight: 700; margin: 14px 0 6px; }
.markdown h2 { font-size: 14px; font-weight: 600; margin: 12px 0 5px; }
.markdown h3 { font-size: 13px; font-weight: 600; margin: 10px 0 4px; }
.markdown ul, .markdown ol { padding-left: 18px; margin: 6px 0; }
.markdown li { margin: 3px 0; }
.markdown code {
  background: #f3f4f6;
  padding: 1px 5px;
  border-radius: 4px;
  font-size: 12px;
  font-family: 'SF Mono', 'Menlo', monospace;
}
.markdown pre {
  background: #f3f4f6;
  padding: 10px 12px;
  border-radius: 8px;
  overflow-x: auto;
  margin: 8px 0;
}
.markdown pre code { background: none; padding: 0; }
.markdown p { margin: 6px 0; }
.markdown a { color: var(--blue); }
.markdown hr { border: none; border-top: 1px solid var(--border); margin: 10px 0; }
.markdown strong { font-weight: 600; }
.markdown blockquote {
  border-left: 3px solid var(--border);
  padding-left: 10px;
  color: var(--muted);
  margin: 6px 0;
}

/* ── Attachments ── */
.attachments { padding-left: 18px; }
.attachments li { margin: 5px 0; }
.attachments a { color: var(--blue); text-decoration: none; font-size: 13px; }

/* ── Settled note box ── */
.settled-note-box {
  margin: 12px 16px;
  background: #f9fafb;
  border-radius: 8px;
  padding: 10px 12px;
  border: 1px solid var(--border);
}
.settled-note-box h4 {
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: .07em;
  color: var(--muted);
  margin-bottom: 4px;
}
.settled-note-box p {
  font-size: 14px;
  line-height: 1.5;
}

/* ── Detail footer (note + buttons) ── */
.detail-footer {
  flex-shrink: 0;
  background: #fff;
  border-top: 1px solid var(--border);
}
.decision-note {
  display: block;
  width: 100%;
  border: none;
  border-bottom: 1px solid var(--border);
  padding: 10px 16px;
  font-size: 14px;
  font-family: inherit;
  resize: none;
  background: #fafafa;
  color: var(--text);
  outline: none;
}
.decision-note:focus {
  background: #fff;
}
.decision-note[hidden] { display: none; }
.action-bar {
  display: flex;
  gap: 10px;
  padding: 10px 16px;
  padding-bottom: calc(10px + env(safe-area-inset-bottom));
}
.action-btn {
  flex: 1;
  padding: 13px 8px;
  border: none;
  border-radius: var(--radius);
  font-size: 15px;
  font-weight: 600;
  cursor: pointer;
  transition: opacity .15s, transform .1s;
  -webkit-tap-highlight-color: transparent;
}
.action-btn:disabled { opacity: .5; }
.action-btn:active { transform: scale(0.96); }
.btn-approve { background: var(--green); color: #fff; }
.btn-reject  { background: var(--red);   color: #fff; }
.btn-defer   { background: var(--amber); color: #fff; }
.btn-return  { background: var(--blue);  color: #fff; }

/* ── Loading ── */
.loading-overlay {
  position: absolute;
  inset: 0;
  background: rgba(255,255,255,.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 100;
}
.loading-overlay[hidden] { display: none; }
.spinner {
  width: 32px;
  height: 32px;
  border: 3px solid var(--border);
  border-top-color: var(--blue);
  border-radius: 50%;
  animation: spin .8s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ── Error banner ── */
#error-banner {
  position: fixed;
  bottom: 80px;
  left: 16px;
  right: 16px;
  background: #fee2e2;
  color: #991b1b;
  padding: 12px 16px;
  border-radius: var(--radius);
  font-size: 14px;
  font-weight: 500;
  z-index: 200;
  text-align: center;
  box-shadow: var(--shadow);
}
#error-banner[hidden] { display: none; }

/* ── Empty state ── */
.empty {
  text-align: center;
  color: var(--muted);
  padding: 48px 16px;
  font-size: 15px;
}
