:root {
  color-scheme: light;
  --bg: #f6f7f8;
  --surface: #ffffff;
  --surface-muted: #f1f3f4;
  --surface-warm: #fff7f1;
  --border: #dfe3e6;
  --border-strong: #b8c0c7;
  --text: #171a1f;
  --muted: #67717c;
  --brand: #ff7300;
  --brand-dark: #c94d00;
  --brand-soft: #fff0e4;
  --ink: #202328;
  --blue: #2563eb;
  --green: #147a48;
  --amber: #a86000;
  --red: #b42318;
  --shadow: 0 18px 48px rgba(24, 28, 33, 0.1);
  --radius: 8px;
  --font: "Segoe UI", "Hiragino Sans", "Yu Gothic UI", "Meiryo", sans-serif;
}

* {
  box-sizing: border-box;
}

html {
  min-height: 100%;
}

body {
  min-height: 100vh;
  margin: 0;
  font-family: var(--font);
  color: var(--text);
  background: var(--bg);
  letter-spacing: 0;
}

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

button {
  cursor: pointer;
}

textarea {
  resize: vertical;
}

[hidden] {
  display: none !important;
}

.auth-view {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(0, 1fr) minmax(360px, 460px);
}

.auth-panel {
  min-height: 100vh;
  padding: 48px;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
  background:
    linear-gradient(120deg, rgba(255, 115, 0, 0.08), rgba(255, 255, 255, 0) 46%),
    var(--surface);
}

.auth-brand {
  display: flex;
  align-items: center;
  gap: 18px;
}

.auth-brand img {
  width: min(260px, 44vw);
  height: auto;
  display: block;
}

.auth-brand h1,
.auth-copy h2,
.brand h1,
.brand p,
.eyebrow,
.panel h3,
.topbar h2,
.empty-state h4,
.dialog h3,
.panel-subtext,
.report-meta {
  margin: 0;
}

.auth-copy {
  max-width: 700px;
}

.auth-copy h2 {
  max-width: 760px;
  font-size: clamp(36px, 6vw, 72px);
  line-height: 1.02;
  letter-spacing: 0;
}

.auth-copy p {
  max-width: 620px;
  color: var(--muted);
  font-size: 18px;
  line-height: 1.8;
}

.auth-card {
  min-height: 100vh;
  padding: 40px;
  display: flex;
  flex-direction: column;
  justify-content: center;
  border-left: 1px solid var(--border);
  background: #fafbfc;
}

.segmented {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  padding: 4px;
  margin-bottom: 18px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-muted);
}

.segment {
  min-height: 38px;
  border: 0;
  border-radius: 6px;
  color: var(--muted);
  background: transparent;
  font-weight: 800;
}

.segment.is-active {
  color: var(--text);
  background: var(--surface);
  box-shadow: 0 1px 4px rgba(24, 28, 33, 0.08);
}

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: minmax(270px, 330px) 1fr;
}

.sidebar {
  min-height: 100vh;
  padding: 22px;
  display: flex;
  flex-direction: column;
  gap: 18px;
  border-right: 1px solid var(--border);
  background: #ffffff;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand img {
  width: 48px;
  height: 48px;
  object-fit: contain;
  flex: 0 0 auto;
}

.brand h1 {
  font-size: 18px;
  line-height: 1.15;
}

.brand p {
  max-width: 210px;
  color: var(--muted);
  font-size: 12px;
  overflow-wrap: anywhere;
}

.logout-button {
  margin-top: auto;
}

.button,
.icon-button,
.mini-button {
  border: 1px solid transparent;
  border-radius: var(--radius);
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  transition: background 0.15s ease, border-color 0.15s ease, color 0.15s ease, transform 0.15s ease;
}

.button {
  min-height: 40px;
  padding: 0 14px;
  font-weight: 800;
  white-space: nowrap;
}

.button svg,
.icon-button svg,
.mini-button svg,
.search-field svg,
.meta-line svg {
  width: 18px;
  height: 18px;
  flex: 0 0 auto;
}

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

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

.button-secondary {
  color: var(--text);
  border-color: var(--border);
  background: var(--surface);
}

.button-secondary:hover {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.button-danger {
  color: var(--red);
  border-color: rgba(180, 35, 24, 0.24);
  background: #fff8f7;
}

.button-full {
  width: 100%;
}

.button:disabled,
.icon-button:disabled,
.mini-button:disabled {
  cursor: not-allowed;
  opacity: 0.5;
}

.icon-button,
.mini-button {
  width: 40px;
  height: 40px;
  padding: 0;
  color: var(--text);
  border-color: var(--border);
  background: var(--surface);
}

.mini-button {
  width: 34px;
  height: 34px;
}

.icon-button:hover,
.mini-button:hover {
  border-color: var(--border-strong);
  background: var(--surface-muted);
}

.form-stack,
.form-grid {
  display: grid;
  gap: 14px;
}

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

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

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

.field span,
.switch span,
.code-box span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.field input,
.field select,
.field textarea,
.select-control {
  width: 100%;
  min-height: 40px;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  background: var(--surface);
  outline: 0;
}

.field textarea {
  min-height: 96px;
  line-height: 1.55;
}

.field input:focus,
.field select:focus,
.field textarea:focus,
.search-field:focus-within,
.select-control:focus {
  border-color: var(--brand);
  box-shadow: 0 0 0 3px rgba(255, 115, 0, 0.14);
}

.search-field {
  min-height: 40px;
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 0 12px;
  color: var(--muted);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.search-field input {
  min-width: 0;
  width: 100%;
  border: 0;
  outline: 0;
  background: transparent;
  color: var(--text);
}

.search-field.compact {
  width: min(260px, 100%);
}

.main {
  min-width: 0;
  padding: 22px;
}

.topbar,
.panel-header,
.dialog-header,
.dialog-actions,
.task-toolbar,
.project-tools,
.dialog-action-group,
.report-controls {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.topbar {
  min-height: 66px;
  margin-bottom: 16px;
}

.topbar h2 {
  font-size: 26px;
  overflow-wrap: anywhere;
}

.topbar-actions,
.task-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  flex-wrap: wrap;
}

.eyebrow {
  color: var(--brand);
  font-size: 11px;
  font-weight: 900;
  text-transform: uppercase;
}

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

.stat-tile,
.panel,
.notification-panel,
.client-item,
.project-item,
.task-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

.stat-tile {
  min-height: 84px;
  padding: 16px;
  display: grid;
  align-content: center;
  gap: 5px;
}

.stat-tile span {
  color: var(--muted);
  font-size: 12px;
  font-weight: 800;
}

.stat-tile strong {
  font-size: 28px;
  line-height: 1;
}

.stat-tile.danger strong {
  color: var(--red);
}

.notification-panel {
  min-height: 56px;
  margin-bottom: 14px;
  padding: 12px;
  display: grid;
  gap: 8px;
}

.notification-item {
  display: grid;
  grid-template-columns: auto 1fr auto;
  align-items: center;
  gap: 10px;
  padding: 10px;
  border-radius: 7px;
  background: #f7f9fb;
}

.notification-item strong {
  font-size: 13px;
}

.notification-item p {
  margin: 2px 0 0;
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.notification-item svg {
  width: 18px;
  height: 18px;
  color: var(--brand);
}

.notification-item.danger svg {
  color: var(--red);
}

.notification-item.warning svg {
  color: var(--amber);
}

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(290px, 380px) minmax(0, 1fr);
  gap: 14px;
  align-items: start;
}

.panel {
  min-width: 0;
  padding: 16px;
}

.projects-panel,
.tasks-panel {
  min-height: 520px;
}

.panel h3 {
  font-size: 18px;
}

.panel-subtext {
  margin-top: 4px;
  color: var(--muted);
  font-size: 13px;
}

.client-list,
.project-list {
  display: flex;
  flex-direction: column;
  gap: 8px;
  overflow: auto;
}

.client-list {
  padding-right: 2px;
}

.project-list {
  margin-top: 14px;
  max-height: calc(100vh - 335px);
}

.client-item,
.project-item {
  padding: 12px;
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  align-items: center;
  gap: 10px;
}

.client-item:hover,
.client-item.is-active,
.project-item:hover,
.project-item.is-active {
  border-color: var(--brand);
  background: var(--brand-soft);
}

.client-select,
.project-select {
  min-width: 0;
  padding: 0;
  border: 0;
  color: inherit;
  background: transparent;
  text-align: left;
}

.client-name,
.project-name,
.task-title {
  display: block;
  font-weight: 900;
  overflow-wrap: anywhere;
}

.client-meta,
.project-meta,
.task-description,
.meta-line {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.45;
}

.item-actions,
.task-actions {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
  justify-content: flex-end;
}

.count-pill,
.status-pill,
.priority-pill,
.archive-pill {
  min-height: 24px;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  padding: 0 8px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 900;
  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--muted);
}

.status-pill.active,
.status-pill.doing,
.status-pill.review {
  color: var(--blue);
  background: #eef4ff;
  border-color: #b9cef9;
}

.status-pill.completed,
.status-pill.done {
  color: var(--green);
  background: #ecf8f1;
  border-color: #b6e4ca;
}

.status-pill.paused {
  color: var(--amber);
  background: #fff5df;
  border-color: #f0d19c;
}

.priority-pill.high {
  color: var(--red);
  border-color: #f2b7b1;
  background: #fff0ee;
}

.archive-pill {
  color: #555d66;
  background: #eef0f2;
}

.switch {
  display: inline-flex;
  align-items: center;
  gap: 7px;
  white-space: nowrap;
}

.switch input {
  accent-color: var(--brand);
}

.task-board {
  margin-top: 14px;
  display: grid;
  grid-template-columns: repeat(4, minmax(180px, 1fr));
  gap: 10px;
  overflow: auto;
}

.task-column {
  min-width: 180px;
  display: grid;
  align-content: start;
  gap: 8px;
}

.task-column-header {
  position: sticky;
  top: 0;
  z-index: 1;
  min-height: 38px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 10px;
  border-radius: var(--radius);
  background: var(--ink);
  color: #ffffff;
  font-size: 13px;
  font-weight: 900;
}

.task-card {
  padding: 12px;
  display: grid;
  gap: 10px;
}

.task-card.overdue {
  border-color: #f0aaa3;
}

.task-meta-grid {
  display: grid;
  gap: 5px;
}

.meta-line {
  display: flex;
  align-items: center;
  gap: 6px;
  min-width: 0;
}

.meta-line span {
  overflow-wrap: anywhere;
}

.attachment-list,
.attachment-fields {
  grid-column: 1 / -1;
  display: grid;
  gap: 10px;
}

.attachment-row {
  min-height: 36px;
  padding: 8px 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: #fafbfc;
}

.attachment-row a {
  min-width: 0;
  color: var(--brand-dark);
  font-weight: 800;
  text-decoration: none;
  overflow-wrap: anywhere;
}

.empty-state {
  padding: 28px 18px;
  display: grid;
  gap: 10px;
  place-items: center;
  text-align: center;
  color: var(--muted);
}

.empty-state h4 {
  color: var(--text);
  font-size: 16px;
}

.empty-state p {
  margin: 0;
  line-height: 1.6;
}

.dialog {
  width: min(860px, calc(100vw - 32px));
  padding: 0;
  border: 0;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
}

.dialog::backdrop {
  background: rgba(24, 28, 33, 0.42);
}

.dialog-inner {
  padding: 20px;
  display: grid;
  gap: 16px;
  background: var(--surface);
}

.dialog-header {
  padding-bottom: 12px;
  border-bottom: 1px solid var(--border);
}

.dialog-actions {
  padding-top: 4px;
}

.report-dialog,
.ai-dialog {
  width: min(760px, calc(100vw - 32px));
}

.line-dialog {
  width: min(680px, calc(100vw - 32px));
}

.report-text {
  width: 100%;
  min-height: 360px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  line-height: 1.65;
  background: #fbfcfd;
}

.report-scope-field {
  min-width: 240px;
}

.line-status,
.line-code-result,
.ai-result {
  min-height: 48px;
  padding: 12px;
  border-radius: var(--radius);
  border: 1px solid var(--border);
  background: #fbfcfd;
  color: var(--muted);
  line-height: 1.65;
  white-space: pre-wrap;
}

.ai-result {
  color: var(--text);
}

.code-box {
  display: grid;
  gap: 6px;
}

.code-box code {
  display: block;
  padding: 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  overflow-wrap: anywhere;
  background: #111827;
  color: #ffffff;
}

.toast {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 20;
  max-width: min(420px, calc(100vw - 40px));
  padding: 12px 14px;
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  color: #ffffff;
  background: var(--ink);
  opacity: 0;
  transform: translateY(10px);
  pointer-events: none;
  transition: opacity 0.18s ease, transform 0.18s ease;
}

.toast.is-visible {
  opacity: 1;
  transform: translateY(0);
}

@media (max-width: 1160px) {
  .workspace-grid,
  .task-board {
    grid-template-columns: 1fr;
  }

  .project-list {
    max-height: none;
  }
}

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

  .auth-panel,
  .auth-card,
  .sidebar {
    min-height: auto;
  }

  .auth-panel,
  .auth-card {
    padding: 28px;
  }

  .sidebar {
    border-right: 0;
    border-bottom: 1px solid var(--border);
  }

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

  .topbar,
  .panel-header,
  .dialog-actions {
    align-items: flex-start;
    flex-direction: column;
  }
}

@media (max-width: 640px) {
  .main {
    padding: 14px;
  }

  .auth-brand {
    align-items: flex-start;
    flex-direction: column;
  }

  .auth-copy h2 {
    font-size: 34px;
  }

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

  .topbar-actions,
  .task-toolbar,
  .dialog-action-group,
  .report-controls {
    width: 100%;
    align-items: stretch;
    flex-direction: column;
  }

  .button,
  .search-field.compact,
  .select-control {
    width: 100%;
  }

  .client-item,
  .project-item {
    grid-template-columns: 1fr;
  }

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