:root {
  --bg: #f5f6f8;
  --panel: #ffffff;
  --text: #162033;
  --muted: #667085;
  --line: #d9dee7;
  --primary: #1f6feb;
  --primary-dark: #185abc;
  --danger: #c0342b;
  --success: #137333;
}

* {
  box-sizing: border-box;
}

html,
body {
  height: 100%;
}

body {
  margin: 0;
  font-family: Arial, "Noto Sans TC", sans-serif;
  color: var(--text);
  background: var(--bg);
  overflow: hidden;
}

a {
  color: inherit;
}

.app-shell {
  height: 100vh;
  display: grid;
  grid-template-columns: 240px minmax(0, 1fr);
  overflow: hidden;
}

.sidebar {
  background: #172033;
  color: #eef2f8;
  height: 100vh;
  overflow-y: auto;
  padding: 20px 14px;
}

.brand {
  display: block;
  padding: 8px 10px 18px;
  font-weight: 700;
  text-decoration: none;
}

.nav {
  display: grid;
  gap: 12px;
}

.nav-group {
  display: grid;
  gap: 4px;
}

.nav-section-title {
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  color: #93a0b8;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0;
  margin: 4px 2px 0;
  padding: 14px 8px 0;
}

.project-context {
  border-top: 1px solid rgba(255, 255, 255, 0.14);
  color: #d7deeb;
  display: grid;
  gap: 5px;
  margin: 4px 2px 0;
  padding: 14px 8px 8px;
}

.project-context-label {
  color: #93a0b8;
  font-size: 12px;
  font-weight: 700;
}

.project-context strong {
  color: #ffffff;
  font-size: 14px;
  line-height: 1.35;
  max-width: 180px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.project-context span:last-child {
  color: #93a0b8;
  font-size: 12px;
}

.project-nav .nav-link {
  padding-left: 24px;
  font-size: 15px;
}

.nav-link {
  display: block;
  padding: 10px 12px;
  border-radius: 6px;
  color: #d7deeb;
  text-decoration: none;
}

.nav-link:hover,
.nav-link.active {
  background: #25314a;
  color: #ffffff;
}

.nav-link.disabled {
  opacity: 0.45;
  pointer-events: none;
}

.button.disabled {
  opacity: 0.5;
  pointer-events: none;
}

.main {
  height: 100vh;
  overflow-y: auto;
  padding: 32px;
}

.page-header {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  align-items: end;
  margin-bottom: 20px;
}

.page-header h1 {
  margin: 0;
  font-size: 30px;
  line-height: 1.2;
}

.page-header p,
.helper,
.muted {
  color: var(--muted);
}

.page-header p {
  margin: 8px 0 0;
}

.current-project-line {
  font-size: 14px;
}

.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  align-items: center;
  margin-bottom: 16px;
}

.card,
.form-card,
.empty-state {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 18px;
}

.grid {
  display: grid;
  gap: 16px;
}

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

.project-list {
  display: grid;
  gap: 12px;
}

.project-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 14px;
  align-items: center;
}

.project-row h2,
.empty-state h2 {
  margin: 0 0 8px;
  font-size: 19px;
}

.project-row p,
.empty-state p {
  margin: 0;
  color: var(--muted);
}

.actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.button,
button {
  border: 1px solid var(--line);
  border-radius: 6px;
  background: #ffffff;
  color: var(--text);
  cursor: pointer;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-height: 38px;
  padding: 8px 13px;
  font: inherit;
  text-decoration: none;
}

.button.primary,
button.primary {
  background: var(--primary);
  border-color: var(--primary);
  color: #ffffff;
}

.button.primary:hover,
button.primary:hover {
  background: var(--primary-dark);
}

button.danger {
  border-color: #f0c8c5;
  color: var(--danger);
}

.form-card {
  display: grid;
  gap: 18px;
}

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

.field span {
  font-weight: 700;
}

.field-title {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.inline-check {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 400;
  white-space: nowrap;
}

.inline-check input {
  width: auto;
}

.helper {
  margin: -2px 0 0;
  font-size: 13px;
}

input,
textarea,
select {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px 11px;
  color: var(--text);
  font: inherit;
  background: #ffffff;
}

textarea {
  resize: vertical;
}

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

.check-row {
  display: flex;
  gap: 8px;
  align-items: center;
  color: var(--text);
}

.check-row input {
  width: auto;
}

.section-choice {
  align-items: flex-start;
}

.section-choice > span {
  display: grid;
  gap: 5px;
}

.generated-card pre {
  background: #f7f8fa;
  border: 1px solid var(--line);
  border-radius: 6px;
  margin: 12px 0 0;
  max-height: 300px;
  overflow: auto;
  padding: 12px;
  white-space: pre-wrap;
}

.progress-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
}

.progress-header {
  display: flex;
  justify-content: space-between;
  margin-bottom: 10px;
}

.progress-track {
  background: #e8edf5;
  border-radius: 999px;
  height: 10px;
  overflow: hidden;
}

.progress-bar {
  background: var(--primary);
  height: 100%;
  transition: width 0.3s ease;
  width: 0;
}

.is-busy {
  opacity: 0.82;
}

.token-usage {
  display: grid;
  grid-template-columns: repeat(4, minmax(110px, 1fr));
  gap: 10px;
  margin: 12px 0;
}

.token-usage div {
  border: 1px solid var(--line);
  border-radius: 6px;
  padding: 10px;
}

.token-usage dt {
  color: var(--muted);
  font-size: 12px;
  margin-bottom: 4px;
}

.token-usage dd {
  font-weight: 700;
  margin: 0;
}

.status {
  min-height: 22px;
  color: var(--muted);
}

.status.success {
  color: var(--success);
}

.status.error {
  color: var(--danger);
}

.divider {
  border: 0;
  border-top: 1px solid var(--line);
  width: 100%;
}

.sample-text-panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 0;
}

.sample-text-panel summary {
  cursor: pointer;
  font-weight: 700;
  padding: 12px 14px;
}

.sample-text-panel .field {
  border-top: 1px solid var(--line);
  padding: 14px;
}

.editor-layout {
  display: grid;
  grid-template-columns: 260px minmax(0, 1fr);
  gap: 18px;
}

.editor-section-list {
  align-self: start;
  display: grid;
  gap: 8px;
  position: sticky;
  top: 0;
}

.section-tab {
  display: grid;
  gap: 4px;
  justify-content: start;
  min-height: auto;
  padding: 12px;
  text-align: left;
}

.section-tab.active {
  border-color: var(--primary);
  box-shadow: 0 0 0 1px var(--primary);
}

.section-tab span {
  color: var(--muted);
  font-size: 13px;
}

.editor-workspace {
  display: grid;
  gap: 14px;
}

.editor-toolbar {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  padding: 10px;
  position: sticky;
  top: -16px;
  z-index: 2;
}

.editor-toolbar button.active {
  background: #e8f0fe;
  border-color: var(--primary);
  color: var(--primary);
  font-weight: 700;
}

.toolbar-divider {
  align-self: stretch;
  border-left: 1px solid var(--line);
  margin: 2px 4px;
}

.document-editor {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  font-family: "Noto Sans TC", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.8;
  min-height: 68vh;
  padding: 42px 54px;
}

.word-page {
  background: #ffffff;
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 1px 2px rgba(16, 24, 40, 0.06);
  font-family: "Noto Sans TC", Arial, sans-serif;
  font-size: 16px;
  line-height: 1.85;
  min-height: 68vh;
  outline: none;
  padding: 48px 64px;
}

.word-page:focus {
  border-color: var(--primary);
  box-shadow: 0 0 0 2px rgba(31, 111, 235, 0.12);
}

.word-page h1,
.word-page h2,
.word-page h3 {
  color: var(--text);
  line-height: 1.35;
  margin: 1.1em 0 0.45em;
}

.word-page h2 {
  border-bottom: 1px solid var(--line);
  font-size: 24px;
  padding-bottom: 8px;
}

.word-page h3 {
  font-size: 19px;
}

.word-page h4 {
  font-size: 17px;
  margin: 1em 0 0.4em;
}

.word-page h5,
.word-page h6 {
  font-size: 16px;
  margin: 0.9em 0 0.35em;
}

.word-page p {
  margin: 0 0 1em;
}

.word-page img {
  border: 1px solid var(--line);
  border-radius: 6px;
  display: block;
  height: auto;
  margin: 16px auto;
  max-width: 100%;
}

.word-page ul {
  margin: 0 0 1em 1.4em;
  padding: 0;
}

.word-page table {
  border-collapse: collapse;
  margin: 18px 0;
  table-layout: fixed;
  width: 100%;
}

.word-page th,
.word-page td {
  border: 1px solid #b8c2d2;
  padding: 9px 10px;
  vertical-align: top;
}

.word-page th {
  background: #eef2f7;
  font-weight: 700;
}

.markdown-source {
  font-family: Consolas, "Courier New", monospace;
}

.revision-panel {
  margin-bottom: 40px;
}

.ai-context-menu {
  background: #1f2937;
  border: 1px solid #374151;
  border-radius: 8px;
  box-shadow: 0 12px 30px rgba(15, 23, 42, 0.28);
  display: grid;
  min-width: 190px;
  padding: 6px;
  position: fixed;
  z-index: 30;
}

.ai-context-menu[hidden] {
  display: none;
}

.ai-context-menu button {
  background: transparent;
  border: 0;
  border-radius: 5px;
  color: #f8fafc;
  justify-content: flex-start;
  min-height: 34px;
  padding: 7px 10px;
}

.ai-context-menu button:hover {
  background: #374151;
}

.modal-backdrop {
  align-items: center;
  background: rgba(15, 23, 42, 0.42);
  display: flex;
  inset: 0;
  justify-content: center;
  padding: 24px;
  position: fixed;
  z-index: 40;
}

.modal-backdrop[hidden] {
  display: none;
}

.modal {
  background: #ffffff;
  border-radius: 8px;
  box-shadow: 0 24px 60px rgba(15, 23, 42, 0.24);
  display: grid;
  gap: 14px;
  max-height: calc(100vh - 48px);
  max-width: 900px;
  overflow: auto;
  padding: 20px;
  width: min(900px, 100%);
}

.modal h2 {
  margin: 0;
}

.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  justify-content: flex-end;
}

.generated-image-preview {
  border: 1px dashed var(--line);
  border-radius: 8px;
  min-height: 120px;
  padding: 12px;
}

.generated-image-preview:empty::before {
  color: var(--muted);
  content: "圖片預覽會顯示在這裡";
}

.generated-image-preview img {
  border-radius: 6px;
  display: block;
  height: auto;
  max-height: 420px;
  max-width: 100%;
  object-fit: contain;
}

@media (max-width: 780px) {
  .app-shell {
    height: auto;
    grid-template-columns: 1fr;
    overflow: visible;
  }

  .sidebar {
    height: auto;
    overflow: visible;
    position: static;
  }

  .main {
    height: auto;
    overflow: visible;
    padding: 20px;
  }

  .grid.two,
  .check-grid,
  .project-row,
  .editor-layout {
    grid-template-columns: 1fr;
  }

  .actions {
    justify-content: flex-start;
  }
}
