:root {
  --bg: #f4f1ec;
  --surface: #ffffff;
  --text: #201c18;
  --text-muted: #6b6055;
  --border: #e2dcd3;
  --accent: #a3402c;
  --accent-text: #ffffff;
  --aging: #4b7c5a;
  --aging-bg: #e4efe6;
  --due-soon: #a06b12;
  --due-soon-bg: #faf0d9;
  --ready: #1f6f6b;
  --ready-bg: #dff1ef;
  --overdue: #b3261e;
  --overdue-bg: #fbe3e1;
  --danger: #b3261e;
}

@media (prefers-color-scheme: dark) {
  :root {
    --bg: #151312;
    --surface: #221f1c;
    --text: #f2ece5;
    --text-muted: #a89d92;
    --border: #35302b;
    --accent: #d97a5f;
    --accent-text: #1a1a1a;
    --aging: #7fc794;
    --aging-bg: #1d2b21;
    --due-soon: #e0b04c;
    --due-soon-bg: #2e2717;
    --ready: #5fc9c3;
    --ready-bg: #17302e;
    --overdue: #ff7a70;
    --overdue-bg: #351a18;
    --danger: #ff7a70;
  }
}

* { box-sizing: border-box; }

[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
}

body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, Helvetica, Arial, sans-serif;
  padding-top: env(safe-area-inset-top);
  padding-right: env(safe-area-inset-right);
  padding-bottom: env(safe-area-inset-bottom);
  padding-left: env(safe-area-inset-left);
  min-height: 100vh;
}

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border: 0;
}

.app-header {
  padding: 20px 16px 8px;
}

.app-header h1 {
  font-size: 22px;
  margin: 0;
  font-weight: 700;
}

main {
  padding: 0 16px 32px;
  max-width: 560px;
  margin: 0 auto;
}

.add-panel {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 16px;
  margin: 12px 0 20px;
}

.field {
  margin-bottom: 12px;
}

label {
  display: block;
  font-size: 13px;
  color: var(--text-muted);
  margin-bottom: 6px;
}

input[type="date"] {
  -webkit-appearance: none;
  appearance: none;
  width: 100%;
  font-size: 16px;
  padding: 12px 14px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--bg);
  color: var(--text);
  min-height: 44px;
  text-align: center;
  display: flex;
  align-items: center;
  justify-content: center;
}

input[type="date"]:focus {
  outline: 2px solid var(--accent);
  outline-offset: 1px;
}

.due-preview {
  font-size: 15px;
  font-weight: 600;
  color: var(--accent);
  margin: 4px 0 14px;
}

.btn-primary {
  width: 100%;
  min-height: 48px;
  font-size: 17px;
  font-weight: 700;
  color: var(--accent-text);
  background: var(--accent);
  border: none;
  border-radius: 12px;
  cursor: pointer;
}

.btn-primary:active {
  opacity: 0.85;
}

.entry-list {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.entry-row {
  position: relative;
  border-radius: 14px;
  overflow: hidden;
  border: 1px solid var(--border);
}

.row-delete-bg {
  position: absolute;
  inset: 0;
  background: var(--danger);
  color: #fff;
  display: flex;
  align-items: center;
  justify-content: flex-end;
  padding-right: 20px;
  font-size: 14px;
  font-weight: 700;
  min-height: 44px;
}

.row-content {
  position: relative;
  background: var(--surface);
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 14px;
  touch-action: pan-y;
  transform: translateX(0);
  transition: transform 0.18s ease;
  will-change: transform;
}

.row-main {
  flex: 1;
  min-width: 0;
}

.row-label {
  margin: 0 0 2px;
  font-weight: 600;
  font-size: 15px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

.row-dates {
  margin: 0;
  font-size: 12.5px;
  color: var(--text-muted);
}

.row-status {
  display: flex;
  flex-direction: column;
  align-items: flex-end;
  gap: 3px;
  flex-shrink: 0;
}

.status-pill {
  font-size: 11px;
  font-weight: 700;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  padding: 3px 8px;
  border-radius: 999px;
  white-space: nowrap;
}

.status-detail {
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.status-aging .status-pill { background: var(--aging-bg); color: var(--aging); }
.status-due-soon .status-pill { background: var(--due-soon-bg); color: var(--due-soon); }
.status-ready .status-pill { background: var(--ready-bg); color: var(--ready); }
.status-overdue .status-pill { background: var(--overdue-bg); color: var(--overdue); }
.status-overdue .status-detail { color: var(--overdue); font-weight: 600; }

.entry-row.open .row-content {
  transform: translateX(-84px);
}

.row-delete-btn {
  display: none;
}

@media (hover: hover) and (pointer: fine) {
  .row-delete-btn {
    display: block;
    min-width: 44px;
    min-height: 44px;
    border: none;
    background: transparent;
    color: var(--danger);
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    flex-shrink: 0;
  }
}

.empty-state {
  text-align: center;
  padding: 48px 16px;
  color: var(--text-muted);
}

.empty-state p {
  margin: 4px 0;
}

.empty-sub {
  font-size: 13px;
}

.toast {
  position: fixed;
  left: 16px;
  right: 16px;
  bottom: calc(20px + env(safe-area-inset-bottom));
  background: var(--text);
  color: var(--bg);
  border-radius: 12px;
  padding: 12px 16px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  font-size: 14px;
  box-shadow: 0 8px 24px rgba(0,0,0,0.25);
  z-index: 100;
}

.toast-undo {
  min-height: 32px;
  padding: 0 10px;
  background: transparent;
  border: 1px solid var(--bg);
  color: var(--bg);
  border-radius: 8px;
  font-weight: 700;
  font-size: 13px;
  cursor: pointer;
  flex-shrink: 0;
}
