:root {
  --bg: #f4f7f6;
  --shell: #e7ecea;
  --surface: #ffffff;
  --surface-soft: #f8faf9;
  --surface-tint: #edf7f4;
  --ink: #17201d;
  --muted: #67736f;
  --soft: #8b9692;
  --line: #dbe3e0;
  --line-strong: #c8d2ce;
  --primary: #156a5b;
  --primary-strong: #0e4f44;
  --primary-soft: #dff3ed;
  --blue: #315f92;
  --blue-soft: #e4eef9;
  --amber: #9d641f;
  --amber-soft: #f7ead8;
  --red: #a94242;
  --red-soft: #f7e5e2;
  --shadow-sm: 0 1px 2px rgba(25, 39, 35, 0.06);
  --shadow-md: 0 16px 45px rgba(25, 39, 35, 0.09);
  --radius: 8px;
  font-family: Inter, "Noto Sans TC", "Microsoft JhengHei", system-ui, sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
  background: var(--bg);
}

body {
  margin: 0;
  min-height: 100vh;
  color: var(--ink);
  background:
    linear-gradient(180deg, rgba(255, 255, 255, 0.68), rgba(255, 255, 255, 0) 280px),
    var(--bg);
}

button,
input,
select,
textarea {
  font: inherit;
}

button {
  cursor: pointer;
}

a {
  color: inherit;
  text-decoration: none;
}

.app-shell {
  width: min(1480px, calc(100% - 28px));
  min-height: calc(100vh - 28px);
  margin: 14px auto;
  display: grid;
  grid-template-columns: 238px minmax(0, 1fr);
  background: rgba(255, 255, 255, 0.72);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow-md);
  overflow: hidden;
}

.topbar {
  grid-column: 2;
  grid-row: 1;
  min-height: 82px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 20px;
  padding: 18px 24px;
  background: rgba(255, 255, 255, 0.86);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(16px);
}

.topbar h1 {
  margin: 2px 0 0;
  font-size: 24px;
  line-height: 1.18;
  letter-spacing: 0;
}

.topbar h1::before {
  content: "學";
  display: inline-grid;
  place-items: center;
  width: 34px;
  height: 34px;
  margin-right: 10px;
  border-radius: 8px;
  background: var(--ink);
  color: #fff;
  font-size: 12px;
  font-weight: 900;
  vertical-align: middle;
}

.eyebrow {
  margin: 0;
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.topbar-actions,
.button-row,
.inline-actions {
  display: flex;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
}

.tabs {
  grid-column: 1;
  grid-row: 1 / span 2;
  display: flex;
  flex-direction: column;
  gap: 6px;
  padding: 104px 14px 18px;
  background: var(--shell);
  border-right: 1px solid var(--line-strong);
  overflow-y: auto;
}

.tabs::before {
  content: "工作區";
  position: absolute;
  margin-top: -74px;
  margin-left: 4px;
  color: var(--soft);
  font-size: 12px;
  font-weight: 900;
  letter-spacing: 0.08em;
  text-transform: uppercase;
}

.tab,
.ghost-button,
.solid-button,
.danger-button,
.small-button {
  border: 1px solid transparent;
  border-radius: var(--radius);
  min-height: 38px;
  padding: 0 14px;
  background: transparent;
  color: var(--ink);
  white-space: nowrap;
}

.tab {
  position: relative;
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  width: 100%;
  min-height: 42px;
  color: #52605b;
  font-weight: 760;
  text-align: left;
}

.tab::before {
  content: "";
  width: 18px;
  height: 18px;
  border-radius: 6px;
  background: #cad5d1;
  box-shadow: inset 0 0 0 1px rgba(23, 32, 29, 0.04);
}

.tab[data-view="dashboard"]::before {
  background: linear-gradient(135deg, var(--primary), #49a88d);
}

.tab[data-view="library"]::before {
  background: linear-gradient(135deg, var(--blue), #75a3d2);
}

.tab[data-view="rescue"]::before {
  background: linear-gradient(135deg, var(--amber), #d59a4b);
}

.tab[data-view="sessions"]::before {
  background: linear-gradient(135deg, #6b5b95, #a894d1);
}

.tab[data-view="settings"]::before {
  background: linear-gradient(135deg, #596460, #96a39e);
}

.tab.is-active {
  background: rgba(255, 255, 255, 0.92);
  color: var(--ink);
  border-color: var(--line-strong);
  box-shadow: var(--shadow-sm);
}

.ghost-button,
.small-button {
  border-color: var(--line);
  background: var(--surface);
}

.ghost-button:hover,
.small-button:hover {
  border-color: var(--line-strong);
  background: var(--surface-soft);
}

.small-button {
  min-height: 32px;
  padding: 0 10px;
  font-size: 13px;
}

.solid-button {
  background: var(--primary);
  color: #fff;
  border-color: var(--primary);
  box-shadow: 0 8px 18px rgba(21, 106, 91, 0.18);
}

.solid-button:hover {
  background: var(--primary-strong);
}

.danger-button {
  background: var(--red-soft);
  color: var(--red);
  border-color: #ebc4bf;
}

.main {
  grid-column: 2;
  grid-row: 2;
  min-width: 0;
  padding: 22px 24px 40px;
}

.layout-grid {
  display: grid;
  grid-template-columns: minmax(0, 1fr) 360px;
  gap: 16px;
  align-items: start;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.panel,
.metric,
.item-row,
.detail-shell {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow-sm);
}

.panel,
.detail-shell {
  padding: 16px;
}

.panel {
  overflow: hidden;
}

.metric {
  position: relative;
  min-height: 112px;
  padding: 16px;
  overflow: hidden;
}

.metric::after {
  content: "";
  position: absolute;
  right: 14px;
  bottom: 14px;
  width: 44px;
  height: 6px;
  border-radius: 999px;
  background: var(--primary-soft);
}

.metric:nth-child(2)::after {
  background: var(--amber-soft);
}

.metric:nth-child(3)::after {
  background: var(--blue-soft);
}

.metric:nth-child(4)::after {
  background: #eee8fb;
}

.metric dt,
.section-label {
  margin: 0 0 8px;
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.05em;
  text-transform: uppercase;
}

.metric dd {
  margin: 0;
  font-size: 34px;
  line-height: 1;
  font-weight: 900;
}

.panel-header,
.list-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.panel-title {
  margin: 0;
  font-size: 18px;
  line-height: 1.3;
  letter-spacing: 0;
}

.panel-subtitle {
  margin: 5px 0 0;
  color: var(--muted);
  line-height: 1.55;
  font-size: 14px;
}

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 10px;
}

.form-grid.one {
  grid-template-columns: 1fr;
}

.field {
  display: grid;
  gap: 6px;
}

.field.full {
  grid-column: 1 / -1;
}

.field label {
  color: var(--muted);
  font-size: 12px;
  font-weight: 850;
  letter-spacing: 0.02em;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: var(--radius);
  background: #fff;
  color: var(--ink);
  min-height: 42px;
  padding: 9px 11px;
  outline: none;
  transition: border-color 0.15s ease, box-shadow 0.15s ease, background 0.15s ease;
}

input:focus,
select:focus,
textarea:focus {
  border-color: rgba(21, 106, 91, 0.62);
  box-shadow: 0 0 0 3px rgba(21, 106, 91, 0.12);
}

textarea {
  min-height: 110px;
  resize: vertical;
  line-height: 1.58;
}

.toolbar {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 160px 160px;
  gap: 10px;
  margin-bottom: 12px;
}

.item-list,
.session-list,
.attachment-list,
.chapter-list {
  display: grid;
  gap: 10px;
}

.item-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  padding: 14px;
  transition: border-color 0.15s ease, transform 0.15s ease, box-shadow 0.15s ease;
}

.item-row:hover {
  border-color: var(--line-strong);
  transform: translateY(-1px);
  box-shadow: 0 8px 24px rgba(25, 39, 35, 0.07);
}

.item-row h3,
.chapter-title,
.session-title {
  margin: 0;
  font-size: 16px;
  line-height: 1.35;
  letter-spacing: 0;
}

.item-meta,
.muted,
.session-meta {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
}

.item-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  margin-top: 8px;
}

.tag,
.status-pill,
.type-pill {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  min-height: 24px;
  padding: 0 9px;
  font-size: 12px;
  font-weight: 800;
  background: var(--surface-soft);
  color: var(--muted);
}

.status-pill.in_progress {
  background: var(--primary-soft);
  color: var(--primary-strong);
}

.status-pill.completed {
  background: #e4f1dc;
  color: #3e652d;
}

.status-pill.paused,
.status-pill.backlog {
  background: var(--amber-soft);
  color: var(--amber);
}

.status-pill.archived {
  background: #ecefee;
  color: #66716e;
}

.progress-bar {
  height: 8px;
  border-radius: 999px;
  overflow: hidden;
  background: #eef2f0;
  margin-top: 12px;
}

.progress-fill {
  height: 100%;
  background: linear-gradient(90deg, var(--primary), #42a98e);
  width: 0;
}

.detail-shell {
  display: grid;
  grid-template-columns: 320px minmax(0, 1fr);
  gap: 16px;
}

.side-stack,
.content-stack {
  display: grid;
  gap: 12px;
}

.chapter-row,
.session-row,
.attachment-row,
.next-action-box {
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 13px;
  background: var(--surface);
}

.next-action-box {
  position: relative;
  background: var(--surface-tint);
  border-color: #c7e6dd;
}

.next-action-box h3 {
  margin: 0 0 8px;
  font-size: 20px;
  line-height: 1.28;
}

.next-action-box p:not(.section-label) {
  color: #2b3a36;
  line-height: 1.62;
}

.empty-state {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 24px;
  text-align: center;
  color: var(--muted);
  background: var(--surface-soft);
}

.split-line {
  height: 1px;
  background: var(--line);
  margin: 12px 0;
}

.preview-image {
  max-width: 100%;
  border-radius: var(--radius);
  border: 1px solid var(--line);
  margin-top: 10px;
}

.file-drop {
  border: 1px dashed var(--line-strong);
  border-radius: var(--radius);
  padding: 12px;
  background: var(--surface-soft);
}

.notice {
  padding: 12px;
  border: 1px solid #d8c392;
  background: #fff8df;
  color: #67521b;
  border-radius: var(--radius);
  line-height: 1.6;
}

@media (max-width: 1100px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .topbar,
  .main,
  .tabs {
    grid-column: 1;
  }

  .tabs {
    grid-row: 2;
    flex-direction: row;
    padding: 8px;
    border-right: 0;
    border-bottom: 1px solid var(--line-strong);
    overflow-x: auto;
  }

  .tabs::before {
    content: none;
  }

  .main {
    grid-row: 3;
  }

  .tab {
    width: auto;
    min-width: 132px;
  }

  .layout-grid,
  .detail-shell {
    grid-template-columns: 1fr;
  }

  .dashboard-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }
}

@media (max-width: 700px) {
  .app-shell {
    width: 100%;
    min-height: 100vh;
    margin: 0;
    border: 0;
    border-radius: 0;
  }

  .topbar {
    align-items: stretch;
    flex-direction: column;
    padding: 16px;
  }

  .topbar h1 {
    font-size: 22px;
  }

  .topbar-actions {
    display: grid;
    grid-template-columns: 1fr 1fr;
  }

  .topbar-actions .solid-button {
    grid-column: 1 / -1;
  }

  .main {
    padding: 16px;
  }

  .dashboard-grid,
  .toolbar,
  .form-grid {
    grid-template-columns: 1fr;
  }

  .item-row {
    grid-template-columns: 1fr;
  }

  .tab {
    min-width: 118px;
  }
}
