:root {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Arial, sans-serif;
  color-scheme: light;
  font-size: 16px;
}

* { box-sizing: border-box; }

body[data-theme="light"] {
  --bg: #f4f5f9;
  --surface: #ffffff;
  --surface-soft: #eef0f7;
  --text: #172039;
  --muted: #68728a;
  --line: #e2e5ee;
  --accent: #6254d7;
  --accent-soft: #ebe8ff;
  --danger: #c4485a;
  --soon-text: #b4233d;
  --soon-bg: #fff0f2;
  --soon-border: #f0c7cf;
  --shadow: 0 12px 36px rgba(27, 34, 63, .07);
  color-scheme: light;
}

body[data-theme="dark"] {
  --bg: #11151d;
  --surface: #1b212c;
  --surface-soft: #272e3b;
  --text: #f0f2f7;
  --muted: #a5aec0;
  --line: #343c4a;
  --accent: #a99dff;
  --accent-soft: #302d4a;
  --danger: #ff8799;
  --soon-text: #ffa39b;
  --soon-bg: #432d35;
  --soon-border: #6e4651;
  --shadow: 0 12px 36px rgba(0, 0, 0, .17);
  color-scheme: dark;
}

body[data-theme="purple"] {
  --bg: #140b27;
  --surface: #24143d;
  --surface-soft: #332052;
  --text: #f9f3ff;
  --muted: #c2afd8;
  --line: #493168;
  --accent: #d5a6ff;
  --accent-soft: #442467;
  --danger: #ffa1bc;
  --soon-text: #ffd18a;
  --soon-bg: #4b315b;
  --soon-border: #835b71;
  --shadow: 0 14px 42px rgba(4, 0, 17, .28);
  color-scheme: dark;
}

html, body { margin: 0; min-height: 100%; background: var(--bg); color: var(--text); }
button, input, textarea, select { font: inherit; }
button { cursor: pointer; }
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

.app-shell { min-height: 100dvh; max-width: 780px; margin: 0 auto; padding-bottom: calc(96px + env(safe-area-inset-bottom)); }
.topbar {
  position: sticky; top: 0; z-index: 10; min-height: 63px;
  display: flex; align-items: center; justify-content: space-between; gap: 12px;
  padding: 12px 18px; background: var(--bg); border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}
.topbar-title { flex: 1 1 auto; min-width: 0; font-size: 20px; line-height: 1.2; font-weight: 750; letter-spacing: -.025em; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.topbar-actions { display: flex; align-items: center; gap: 7px; flex-shrink: 0; }
.topbar.stacked-actions { display: grid; grid-template-columns: 42px minmax(0, 1fr); gap: 8px 12px; }
.topbar.stacked-actions .topbar-title { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 2; white-space: normal; overflow-wrap: anywhere; }
.topbar.stacked-actions .topbar-actions { grid-column: 1 / -1; justify-content: flex-end; }
.content { padding: 18px; }
.loading, .empty, .error-panel { padding: 28px 18px; text-align: center; color: var(--muted); }
.error-panel { background: var(--surface); border-radius: 16px; margin-top: 28px; box-shadow: var(--shadow); }

.section { margin-bottom: 26px; }
.section-head { display: flex; align-items: center; justify-content: space-between; gap: 10px; margin: 0 0 10px; }
.section-title { margin: 0; font-size: 17px; font-weight: 740; letter-spacing: -.015em; }
.section-subtitle { margin: 2px 0 14px; color: var(--muted); font-size: 14px; }
.list { display: grid; gap: 8px; }
.list-row {
  width: 100%; padding: 13px 14px; display: block; text-align: left; color: var(--text);
  border: 1px solid var(--line); border-radius: 14px; background: var(--surface); box-shadow: var(--shadow);
}
.list-row:hover, .list-row:focus-visible { border-color: var(--accent); outline: none; }
.row-top { display: flex; align-items: center; gap: 7px; flex-wrap: wrap; margin-bottom: 5px; }
.row-main { display: block; font-size: 15px; font-weight: 650; line-height: 1.4; white-space: pre-wrap; overflow-wrap: anywhere; }
.row-main.clamp { display: -webkit-box; -webkit-box-orient: vertical; -webkit-line-clamp: 3; overflow: hidden; }
.row-meta { display: block; margin-top: 6px; color: var(--muted); font-size: 12px; line-height: 1.4; }
.row-more { margin-top: 7px; color: var(--accent); font-size: 13px; font-weight: 650; }
.badge { display: inline-flex; align-items: center; min-height: 22px; padding: 2px 8px; border-radius: 7px; background: var(--accent-soft); color: var(--accent); font-size: 12px; font-weight: 700; }
.badge.soon { color: var(--soon-text); background: var(--soon-bg); border: 1px solid var(--soon-border); }
.badge.muted { color: var(--muted); background: var(--surface-soft); }
.badge.danger { color: var(--danger); background: var(--surface-soft); }
.subject-row { display: flex; justify-content: space-between; align-items: center; gap: 12px; }
.subject-name { font-size: 16px; font-weight: 680; }
.chevron { color: var(--muted); font-size: 20px; }

.button {
  border: 1px solid transparent; border-radius: 11px; padding: 9px 13px;
  background: var(--accent); color: var(--bg); font-size: 13px; font-weight: 700; white-space: nowrap;
}
.button:hover { filter: brightness(1.08); }
.button.secondary { color: var(--text); background: var(--surface); border-color: var(--line); }
.button.ghost { color: var(--accent); background: var(--accent-soft); }
.button.danger { color: var(--danger); background: var(--surface); border-color: var(--line); }
.button.small { padding: 7px 10px; font-size: 12px; }
.icon-button { flex: 0 0 42px; width: 42px; height: 42px; display: inline-flex; align-items: center; justify-content: center; padding: 0; border-radius: 13px; border: 1px solid var(--line); background: var(--surface); color: var(--text); box-shadow: var(--shadow); }
.icon-button svg { display: block; width: 22px; height: 22px; }
.back-button svg { width: 23px; height: 23px; }
.edit-button { color: var(--accent); background: var(--accent-soft); border-color: transparent; }
.icon-button:focus-visible, .button:focus-visible, .tab:focus-visible { outline: 2px solid var(--accent); outline-offset: 2px; }
.action-row { display: flex; flex-wrap: wrap; gap: 8px; margin: 15px 0; }
.tabs { display: flex; gap: 4px; margin: 0 0 16px; padding: 4px; border-radius: 13px; background: var(--surface-soft); }
.tab { flex: 1; border: 0; border-radius: 10px; padding: 10px 8px; background: transparent; color: var(--muted); font-size: 13px; font-weight: 700; }
.tab.active { color: var(--text); background: var(--surface); box-shadow: var(--shadow); }
.segmented { display: flex; gap: 7px; margin: 12px 0 18px; }
.segmented .button { flex: 1; }
.panel { border: 1px solid var(--line); border-radius: 16px; background: var(--surface); box-shadow: var(--shadow); padding: 16px; margin-bottom: 15px; }
.panel-title { margin: 0 0 10px; font-size: 16px; font-weight: 720; }
.muted { color: var(--muted); }
.small-text { font-size: 13px; }
.detail-body { white-space: pre-wrap; overflow-wrap: anywhere; line-height: 1.6; }
.detail-title { font-size: 20px; margin: 0 0 12px; }
.detail-data { display: grid; gap: 7px; margin: 15px 0; color: var(--muted); font-size: 14px; }
.detail-data strong { color: var(--text); }
.detail-data strong.soon-date { color: var(--soon-text); }
.file-list { display: grid; gap: 7px; margin-top: 10px; }
.file-row { display: flex; align-items: center; gap: 10px; padding: 10px 12px; background: var(--surface-soft); border-radius: 10px; min-width: 0; }
.file-name { flex: 1; min-width: 0; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 13px; }
.file-size { flex-shrink: 0; color: var(--muted); font-size: 12px; }
.file-input { position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px; overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border: 0; }
.file-picker { display: flex; align-items: center; gap: 12px; min-height: 70px; padding: 12px 14px; border: 1px dashed var(--accent); border-radius: 12px; background: var(--accent-soft); color: var(--text); cursor: pointer; }
.file-picker:hover { filter: brightness(1.04); }
.file-input:focus-visible + .file-picker { outline: 2px solid var(--accent); outline-offset: 2px; }
.file-picker-icon { flex: none; width: 38px; height: 38px; display: grid; place-items: center; border-radius: 10px; background: var(--accent); color: var(--bg); font-size: 25px; line-height: 1; font-weight: 700; }
.file-picker-copy { display: grid; gap: 3px; min-width: 0; }
.file-picker-copy strong { font-size: 14px; line-height: 1.2; }
.file-picker-copy small { color: var(--muted); font-size: 12px; line-height: 1.25; }

.field { display: block; margin: 0 0 16px; }
.field-label { display: block; margin-bottom: 6px; color: var(--muted); font-size: 13px; font-weight: 680; }
.input, .textarea, .select { width: 100%; border: 1px solid var(--line); border-radius: 11px; background: var(--surface); color: var(--text); padding: 11px 12px; outline: none; }
.input:focus, .textarea:focus, .select:focus { border-color: var(--accent); }
.input.soon-input { color: var(--soon-text); border-color: var(--soon-border); background: var(--soon-bg); }
.textarea { min-height: 120px; resize: vertical; line-height: 1.5; }
.field-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.check-row { display: flex; align-items: center; gap: 10px; margin: 12px 0 18px; font-size: 14px; }
.check-row input { width: 18px; height: 18px; accent-color: var(--accent); }
.form-actions { display: flex; gap: 9px; padding: 11px 0 0; }
.form-actions .button { flex: 1; font-size: 14px; padding: 12px 10px; }
.hint { color: var(--muted); font-size: 12px; line-height: 1.45; margin: 6px 0; }
.form-link { display: grid; grid-template-columns: 1fr 1fr auto; gap: 6px; margin-bottom: 8px; }
.form-link .input { min-width: 0; }

.theme-choice { display: flex; align-items: center; justify-content: space-between; width: 100%; margin: 7px 0; padding: 14px; border: 1px solid var(--line); border-radius: 12px; color: var(--text); background: var(--surface); text-align: left; }
.theme-choice.selected { border-color: var(--accent); box-shadow: inset 0 0 0 1px var(--accent); }
.drag-row { display: flex; align-items: center; gap: 10px; }
.drag-handle { flex: none; padding: 7px; color: var(--muted); touch-action: none; cursor: grab; user-select: none; font-size: 20px; }
.drag-row.moving { opacity: .6; border-color: var(--accent); }
.toast { position: fixed; left: 50%; bottom: calc(90px + env(safe-area-inset-bottom)); z-index: 50; max-width: calc(100vw - 30px); transform: translateX(-50%); padding: 10px 14px; border-radius: 11px; color: var(--text); background: var(--surface); box-shadow: 0 8px 30px rgba(0,0,0,.22); border: 1px solid var(--line); font-size: 13px; opacity: 0; pointer-events: none; transition: opacity .2s; }
.toast.show { opacity: 1; }
.bottom-nav { position: fixed; left: 50%; bottom: 0; transform: translateX(-50%); z-index: 20; width: min(100%, 780px); display: grid; grid-template-columns: repeat(4, 1fr); padding: 9px 8px calc(10px + env(safe-area-inset-bottom)); background: var(--surface); border-top: 1px solid var(--line); box-shadow: 0 -8px 30px rgba(17, 21, 42, .05); }
.bottom-nav.hidden { display: none; }
.nav-button { display: grid; align-content: center; gap: 4px; justify-items: center; min-height: 66px; border: 0; border-radius: 13px; background: transparent; color: var(--muted); padding: 6px 2px; font-size: 12px; font-weight: 650; }
.nav-button.active { color: var(--accent); }
.nav-icon { display: grid; place-items: center; width: 44px; height: 35px; border-radius: 12px; }
.nav-button.active .nav-icon { background: var(--accent-soft); }
.nav-icon svg { display: block; width: 25px; height: 25px; }

@media (min-width: 700px) {
  .content { padding: 24px; }
  .topbar { padding-inline: 24px; }
}
@media (max-width: 390px) {
  .content { padding: 14px; }
  .topbar { padding-inline: 14px; }
  .field-grid { grid-template-columns: 1fr; gap: 0; }
}
