:root {
  --bg: #14171C;
  --bg-card: #1B1F26;
  --bg-card2: #22272F;
  --line: #2A3039;
  --divider: #3A414C;
  --text: #E8ECEF;
  --text-secondary: #8A939D;
  --accent: #E2571F;
  --accent-dim: rgba(226,87,31,0.15);
  --green: #2ECC71;
  --yellow: #F1C40F;
  --blue: #3B82F6;
  --radius: 12px;
  --radius-sm: 8px;
}

* { box-sizing: border-box; margin: 0; padding: 0; -webkit-tap-highlight-color: transparent; }

html, body {
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: -apple-system, 'SF Pro Text', 'Helvetica Neue', sans-serif;
  font-size: 16px;
  line-height: 1.5;
  overscroll-behavior: none;
}

/* ── Layout ── */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 430px;
  margin: 0 auto;
}

/* ── Header ── */
.header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 20px 10px;
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.header-left { display: flex; flex-direction: column; }
.header-logo { font-size: 18px; font-weight: 700; letter-spacing: -0.3px; }
.header-logo span { color: var(--accent); }
.header-sub { font-size: 11px; color: var(--text-secondary); margin-top: 1px; }
.header-right { display: flex; align-items: center; gap: 8px; }

#sync-btn, #settings-btn {
  width: 34px;
  height: 34px;
  border-radius: 50%;
  background: var(--bg-card);
  border: 1px solid var(--line);
  color: var(--text-secondary);
  font-size: 16px;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  transition: background .15s;
}
#sync-btn:active, #settings-btn:active { background: var(--bg-card2); }

/* ── Tabs ── */
.tabs {
  display: flex;
  border-bottom: 1px solid var(--line);
  background: var(--bg);
}
.tab {
  flex: 1;
  padding: 10px 4px;
  text-align: center;
  font-size: 12px;
  font-weight: 500;
  color: var(--text-secondary);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  transition: color .15s, border-color .15s;
}
.tab.active { color: var(--accent); border-bottom-color: var(--accent); }

/* ── Content ── */
.content {
  flex: 1;
  overflow-y: auto;
  padding: 16px;
  padding-bottom: max(24px, env(safe-area-inset-bottom));
}

/* ── Section head ── */
.section-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 10px;
}
.section-title {
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .8px;
}
.section-count { font-size: 13px; color: var(--text-secondary); }

/* ── Cards ── */
.card {
  background: var(--bg-card);
  border-radius: var(--radius);
  padding: 14px 16px;
  margin-bottom: 10px;
  border: 1px solid var(--line);
  cursor: pointer;
  transition: background .12s;
}
.card:active { background: var(--bg-card2); }

.card-top { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; margin-bottom: 4px; }
.card-name { font-size: 15px; font-weight: 600; flex: 1; }
.card-amount { font-size: 15px; font-weight: 700; color: var(--accent); white-space: nowrap; }
.card-service { font-size: 13px; color: var(--text-secondary); margin-bottom: 8px; }
.card-bottom { display: flex; align-items: center; gap: 8px; flex-wrap: wrap; }

.bot-tag {
  display: inline-block;
  font-size: 10px;
  font-weight: 600;
  background: rgba(59,130,246,.18);
  color: var(--blue);
  padding: 1px 6px;
  border-radius: 10px;
  vertical-align: middle;
  margin-left: 4px;
}

.prog-text { font-size: 12px; color: var(--text-secondary); }

/* ── Badges ── */
.badge {
  font-size: 11px;
  font-weight: 600;
  padding: 3px 8px;
  border-radius: 20px;
}
.badge-new    { background: var(--accent-dim); color: var(--accent); }
.badge-work   { background: rgba(59,130,246,.15); color: var(--blue); }
.badge-done   { background: rgba(46,204,113,.15); color: var(--green); }
.badge-closed { background: var(--line); color: var(--text-secondary); }

.deadline { font-size: 12px; color: var(--text-secondary); margin-left: auto; }
.deadline.overdue { color: var(--accent); font-weight: 600; }
.deadline.soon { color: var(--yellow); font-weight: 600; }

/* ── Stats ── */
.stats {
  display: grid;
  grid-template-columns: 1fr 1fr 1fr;
  gap: 10px;
  margin-bottom: 20px;
}
.stat {
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 12px;
  text-align: center;
  border: 1px solid var(--line);
}
.stat-value { font-size: 22px; font-weight: 700; }
.stat-label { font-size: 11px; color: var(--text-secondary); margin-top: 2px; }

/* ── Calendar row ── */
.cal-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-top: 10px;
  flex-wrap: wrap;
  gap: 8px;
}
.gcal-btn {
  font-size: 12px;
  font-weight: 600;
  background: rgba(59,130,246,.12);
  color: var(--blue);
  border: none;
  border-radius: 20px;
  padding: 4px 10px;
  cursor: pointer;
}
.gcal-btn:active { opacity: .7; }
.gcal-btn-inline {
  font-size: 11px;
  font-weight: 600;
  background: rgba(59,130,246,.12);
  color: var(--blue);
  border: none;
  border-radius: 20px;
  padding: 2px 8px;
  cursor: pointer;
  margin-left: 6px;
  vertical-align: middle;
}

/* ── FAB ── */
.fab {
  position: fixed;
  bottom: max(28px, env(safe-area-inset-bottom, 28px));
  right: 20px;
  width: 52px;
  height: 52px;
  border-radius: 50%;
  background: var(--accent);
  color: #fff;
  font-size: 28px;
  border: none;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  box-shadow: 0 4px 20px rgba(226,87,31,.5);
  transition: transform .1s;
  z-index: 20;
  line-height: 1;
}
.fab:active { transform: scale(.93); }

/* ── Modal ── */
.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,.65);
  z-index: 40;
  display: flex;
  align-items: flex-end;
  opacity: 0;
  pointer-events: none;
  transition: opacity .2s;
}
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal {
  background: var(--bg-card);
  border-radius: var(--radius) var(--radius) 0 0;
  width: 100%;
  max-height: 92dvh;
  overflow-y: auto;
  padding: 20px;
  padding-bottom: max(32px, env(safe-area-inset-bottom));
  transform: translateY(40px);
  transition: transform .22s ease-out;
}
.modal-overlay.open .modal { transform: translateY(0); }
.modal-handle { width: 36px; height: 4px; background: var(--divider); border-radius: 2px; margin: 0 auto 20px; }
.modal-title { font-size: 17px; font-weight: 700; margin-bottom: 20px; }

/* ── Form ── */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 11px;
  font-weight: 700;
  color: var(--text-secondary);
  text-transform: uppercase;
  letter-spacing: .6px;
  margin-bottom: 6px;
}
.field input, .field select, .field textarea {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  padding: 11px 14px;
  color: var(--text);
  font-size: 15px;
  font-family: inherit;
  outline: none;
  -webkit-appearance: none;
  appearance: none;
}
.field input:focus, .field select:focus, .field textarea:focus { border-color: var(--accent); }
.field textarea { resize: none; min-height: 72px; }
.field select option { background: var(--bg-card2); }

.btn {
  display: block;
  width: 100%;
  padding: 14px;
  border-radius: var(--radius-sm);
  font-size: 15px;
  font-weight: 600;
  border: none;
  cursor: pointer;
  text-align: center;
  transition: opacity .15s;
  font-family: inherit;
}
.btn:active { opacity: .8; }
.btn-primary { background: var(--accent); color: #fff; }
.btn-secondary { background: var(--line); color: var(--text); margin-top: 8px; }

/* ── Detail view ── */
.detail { display: none; flex-direction: column; height: 100%; }
.detail.open { display: flex; }

.detail-header {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 14px 20px 12px;
  padding-top: max(14px, env(safe-area-inset-top));
  border-bottom: 1px solid var(--line);
  background: var(--bg);
  position: sticky;
  top: 0;
  z-index: 10;
}
.back-btn { background: none; border: none; color: var(--accent); font-size: 15px; cursor: pointer; padding: 0; font-weight: 500; }
.detail-title { font-size: 16px; font-weight: 700; flex: 1; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.detail-body {
  flex: 1;
  overflow-y: auto;
  padding: 16px 20px;
  padding-bottom: max(40px, env(safe-area-inset-bottom));
}

.info-row {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  gap: 12px;
}
.info-row:last-child { border-bottom: none; }
.info-key { font-size: 13px; color: var(--text-secondary); flex-shrink: 0; min-width: 64px; }
.info-val { font-size: 14px; font-weight: 500; text-align: right; flex: 1; }

/* ── Checklist ── */
.check-item {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 0;
  border-bottom: 1px solid var(--line);
  cursor: pointer;
}
.check-item:last-child { border-bottom: none; }
.check-box {
  width: 22px;
  height: 22px;
  border-radius: 6px;
  border: 2px solid var(--divider);
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
  font-size: 13px;
  transition: background .15s, border-color .15s;
}
.check-item.done .check-box { background: var(--green); border-color: var(--green); color: #fff; }
.check-label { font-size: 14px; flex: 1; }
.check-item.done .check-label { text-decoration: line-through; color: var(--text-secondary); }

.add-task-row { display: flex; gap: 8px; margin-top: 10px; }
.add-task-input {
  flex: 1;
  background: var(--bg);
  border: 1px solid var(--divider);
  border-radius: var(--radius-sm);
  padding: 9px 12px;
  color: var(--text);
  font-size: 14px;
  font-family: inherit;
  outline: none;
}
.add-task-input:focus { border-color: var(--accent); }
.add-task-btn {
  background: var(--accent);
  border: none;
  border-radius: var(--radius-sm);
  padding: 0 16px;
  color: #fff;
  font-size: 22px;
  cursor: pointer;
  line-height: 1;
}

/* ── Docs ── */
.doc-item {
  display: flex;
  align-items: center;
  gap: 12px;
  background: var(--bg-card);
  border-radius: var(--radius-sm);
  padding: 12px 14px;
  margin-bottom: 8px;
  border: 1px solid var(--line);
  cursor: pointer;
}
.doc-icon { font-size: 22px; flex-shrink: 0; }
.doc-info { flex: 1; min-width: 0; }
.doc-name { font-size: 14px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.doc-meta { font-size: 12px; color: var(--text-secondary); margin-top: 2px; }
.doc-link {
  font-size: 16px;
  color: var(--blue);
  text-decoration: none;
  padding: 4px;
  flex-shrink: 0;
}
.doc-del {
  background: none;
  border: none;
  color: var(--text-secondary);
  font-size: 14px;
  cursor: pointer;
  padding: 4px;
  flex-shrink: 0;
}
.doc-del:active { color: var(--accent); }

.add-doc-toggle {
  background: none;
  border: none;
  color: var(--accent);
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  padding: 0;
}

/* ── Empty ── */
.empty { text-align: center; padding: 48px 24px; color: var(--text-secondary); }
.empty-icon { font-size: 40px; margin-bottom: 12px; }
.empty-text { font-size: 14px; line-height: 1.7; }
