:root {
  --bg: #0b1220;           /* page background */
  --panel: #101827;        /* card/input bg */
  --panel-2: #0c1526;      /* table bg */
  --text: #e6e8ee;         /* main text */
  --muted: #9aa7b6;        /* secondary text */
  --primary: #22c55e;      /* button gradient start */
  --primary-2: #16a34a;    /* button gradient end */
  --accent: #5cc8ff;       /* numbers */
  --danger: #ef4444;
  --warn: #f59e0b;
  --border: #1e293b;       /* borders */
  --thead-bg: #0e172a;     /* table header */
}

/* Light theme overrides */
:root[data-theme="light"] {
  --bg: #f7f9fc;
  --panel: #ffffff;
  --panel-2: #ffffff;
  --text: #0f172a;
  --muted: #526277;
  --primary: #16a34a;
  --primary-2: #15803d;
  --accent: #0ea5e9;
  --danger: #dc2626;
  --warn: #d97706;
  --border: #e5eaf1;
  --thead-bg: #f1f5f9;
}

* { box-sizing: border-box; }
html, body { height: 100%; }
body {
  margin: 0;
  font-family: system-ui, -apple-system, Segoe UI, Roboto, "Helvetica Neue", Arial, "Noto Sans", "Apple Color Emoji", "Segoe UI Emoji";
  background: var(--bg);
  color: var(--text);
  transition: background-color .2s ease, color .2s ease;
}

.container { max-width: 980px; margin: 32px auto; padding: 0 16px; }
.header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 20px; }

h1, h2 { margin: 0 0 12px; font-weight: 700; }
p { color: var(--muted); }

.card {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 20px;
  box-shadow: 0 6px 20px rgba(0,0,0,0.18);
}

form.grid { display: grid; gap: 12px; }
form.grid-cols-5 { grid-template-columns: repeat(5, minmax(0, 1fr)); }

input, button {
  padding: 12px 14px;
  font-size: 15px;
  border-radius: 12px;
  border: 1px solid var(--border);
  background: var(--panel);
  color: var(--text);
}

input::placeholder { color: var(--muted); }

button {
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-2) 100%);
  color: #041309;
  border: none;
  cursor: pointer;
  font-weight: 700;
  min-height: 44px; /* mobile-friendly target */
}

button.danger { background: linear-gradient(180deg, var(--danger), #dc2626); color: #fff; }

.tabs { display: flex; gap: 12px; margin-bottom: 12px; color: var(--muted); }
.tabs span { cursor: pointer; }
.tabs span.active { color: var(--text); font-weight: 700; }

/* Icon button */
#themeToggle {
  width: 42px;
  height: 42px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}

/* Segmented control */
.seg {
  display: inline-flex;
  border: 1px solid var(--border);
  background: var(--panel);
  border-radius: 10px;
  overflow: hidden;
}
.seg button {
  background: transparent;
  color: var(--muted);
  border: 0;
  padding: 8px 10px;
  min-height: 0;
}
.seg button + button { border-right: 1px solid var(--border); }
.seg button.active {
  background: linear-gradient(180deg, var(--primary) 0%, var(--primary-2) 100%);
  color: #041309;
  font-weight: 700;
}

table { width: 100%; border-collapse: collapse; background: var(--panel-2); border-radius: 12px; overflow: hidden; }
th, td { border-bottom: 1px solid var(--border); padding: 12px; text-align: right; }
thead th { background: var(--thead-bg); color: var(--muted); font-weight: 600; }
td .actions button { padding: 6px 10px; }
tbody tr:nth-child(odd) { background: rgba(92, 200, 255, 0.04); }
tbody tr:hover { background: rgba(34, 197, 94, 0.08); }
:root[data-theme="light"] tbody tr:nth-child(odd) { background: rgba(2, 132, 199, 0.06); }
:root[data-theme="light"] tbody tr:hover { background: rgba(22, 163, 74, 0.10); }

.amount { color: var(--accent); font-weight: 700; }
.remain.ok { color: var(--primary); font-weight: 700; }
.remain.warn { color: var(--warn); font-weight: 700; }
.remain.due { color: var(--danger); font-weight: 700; }

.total { margin: 12px 0 20px; }
.total strong { color: var(--text); }

.footer { margin-top: 20px; color: var(--muted); font-size: 13px; }

/* Helpers */
.muted { color: var(--muted); }
.accent { color: var(--accent); }
.date-input { color: var(--accent); }
input[type="month"].date-input::-webkit-calendar-picker-indicator { filter: hue-rotate(180deg) saturate(140%); }

.chip { display: inline-block; padding: 4px 8px; border-radius: 999px; font-size: 12px; font-weight: 700; }
.chip--start { background: rgba(56, 189, 248, 0.16); color: var(--accent); border: 1px solid rgba(56,189,248,0.35); }
.chip--end { background: rgba(245, 158, 11, 0.16); color: var(--warn); border: 1px solid rgba(245,158,11,0.35); }
.chip--remain { background: rgba(34, 197, 94, 0.16); color: var(--primary); border: 1px solid rgba(34,197,94,0.35); }

/* Responsive */
.table-wrap { width: 100%; overflow-x: auto; }
.cards-mobile { display: none; }

@media (max-width: 640px) {
  .container { margin: 20px auto; padding: 0 12px; }
  h1 { font-size: 20px; }
  h2 { font-size: 16px; }
  .header { gap: 10px; flex-direction: column; align-items: stretch; }
  .header > div { display: grid !important; grid-template-columns: 1fr 1fr; gap: 8px; }
  .header > div > a, .header > div > button { width: 100%; }
  .header button { font-size: 14px; }

  form.grid { gap: 10px; }
  form.grid-cols-5 { grid-template-columns: 1fr; }
  input, button { font-size: 14px; }
  button { width: 100%; }

  table { font-size: 14px; }
  th, td { padding: 10px; }

  /* Turn table into cards on mobile */
  thead { display: none; }
  table, tbody, tr, td { display: block; width: 100%; }
  tbody tr { background: var(--panel-2); margin-bottom: 10px; border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
  td { display: flex; align-items: center; justify-content: space-between; gap: 12px; }
  td::before { content: attr(data-label); color: var(--muted); }

  /* Hide desktop table, use cards list */
  .table-wrap { display: none; }
  .cards-mobile { display: grid; gap: 10px; }
.card-item { background: var(--panel-2); border: 1px solid var(--border); border-radius: 12px; overflow: hidden; }
  .card-item__head { display: flex; align-items: center; justify-content: space-between; padding: 12px; cursor: pointer; }
  .card-item__title { font-weight: 700; }
  .card-item__meta { display: flex; gap: 8px; align-items: center; }
  .card-item__body { display: none; padding: 12px; border-top: 1px solid var(--border); }
  .card-item.expanded .card-item__body { display: block; }
}

