:root {
  --ink: #18231f;
  --paper: #f7f4ed;
  --panel: #fffdf7;
  --line: #d8d0c2;
  --sage: #6f8976;
  --moss: #26362f;
  --clay: #b96445;
  --steel: #415267;
  --focus: #0f766e;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  color: var(--ink);
  background:
    linear-gradient(90deg, rgba(38, 54, 47, 0.06) 1px, transparent 1px),
    linear-gradient(180deg, rgba(38, 54, 47, 0.05) 1px, transparent 1px),
    var(--paper);
  background-size: 28px 28px;
  font-family: "Segoe UI", "Pretendard", system-ui, sans-serif;
}

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

button {
  min-height: 38px;
  border: 1px solid var(--moss);
  border-radius: 6px;
  background: var(--moss);
  color: white;
  cursor: pointer;
}

button:hover {
  filter: brightness(1.05);
}

button:focus-visible,
input:focus-visible,
select:focus-visible,
textarea:focus-visible {
  outline: 3px solid color-mix(in srgb, var(--focus), transparent 62%);
  outline-offset: 2px;
}

.shell {
  display: grid;
  grid-template-columns: 92px 1fr;
  min-height: 100vh;
}

.rail {
  position: sticky;
  top: 0;
  display: flex;
  flex-direction: column;
  height: 100vh;
  border-right: 1px solid var(--line);
  background: rgba(255, 253, 247, 0.88);
  padding: 18px 14px;
}

.mark {
  display: grid;
  width: 48px;
  height: 48px;
  place-items: center;
  border: 2px solid var(--moss);
  border-radius: 6px;
  color: var(--moss);
  font-weight: 800;
}

nav {
  display: grid;
  gap: 12px;
  margin-top: 28px;
}

nav a {
  color: var(--steel);
  font-size: 13px;
  text-decoration: none;
}

nav a.active {
  color: var(--clay);
  font-weight: 700;
}

.rail-account {
  display: grid;
  gap: 4px;
  margin-top: auto;
  padding-top: 18px;
  border-top: 1px solid var(--line);
}

.rail-account strong,
.rail-account span {
  overflow: hidden;
  text-overflow: ellipsis;
}

.rail-account strong {
  font-size: 12px;
}

.rail-account span {
  color: var(--steel);
  font-size: 10px;
}

.rail-account button {
  margin-top: 8px;
  padding: 0 6px;
  font-size: 11px;
}

main {
  width: min(1280px, 100%);
  margin: 0 auto;
  padding: 34px;
}

.topbar {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 26px;
}

.eyebrow,
.muted {
  margin: 0;
  color: var(--steel);
  font-size: 12px;
  font-weight: 700;
  text-transform: uppercase;
}

h1 {
  max-width: 840px;
  margin: 6px 0 0;
  font-family: Georgia, "Times New Roman", serif;
  font-size: 38px;
  line-height: 1.08;
  letter-spacing: 0;
}

h2 {
  margin: 0;
  font-size: 18px;
}

.status-grid {
  display: grid;
  grid-template-columns: repeat(6, minmax(0, 1fr));
  gap: 12px;
  margin-bottom: 18px;
}

.status-grid article,
.panel {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: color-mix(in srgb, var(--panel), transparent 4%);
  box-shadow: 0 12px 32px rgba(38, 54, 47, 0.08);
}

.status-grid article {
  padding: 16px;
}

.status-grid article > span {
  display: block;
  color: var(--steel);
  font-size: 12px;
}

.status-grid strong {
  display: block;
  margin-top: 8px;
  font-size: 30px;
}

.workspace {
  display: grid;
  grid-template-columns: minmax(0, 1.25fr) minmax(340px, 0.75fr);
  gap: 18px;
}

.panel {
  padding: 18px;
}

.panel-head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 14px;
}

.task-form {
  display: grid;
  grid-template-columns: minmax(180px, 1.5fr) minmax(170px, 1fr) 120px 120px 140px;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
  padding: 12px;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

.task-form .wide-field {
  grid-column: span 3;
}

.task-form .form-actions {
  align-self: end;
}

label {
  display: grid;
  gap: 6px;
  color: var(--steel);
  font-size: 12px;
  font-weight: 700;
}

input,
select,
textarea {
  width: 100%;
  min-height: 38px;
  border: 1px solid var(--line);
  border-radius: 6px;
  background: white;
  color: var(--ink);
  padding: 8px 10px;
}

textarea {
  resize: vertical;
  line-height: 1.5;
}

.app-loading {
  position: fixed;
  inset: 0 0 auto;
  z-index: 100;
  height: 3px;
  overflow: hidden;
  background: color-mix(in srgb, var(--sage), transparent 75%);
}

.app-loading span {
  display: block;
  width: 35%;
  height: 100%;
  background: var(--clay);
  animation: loading-slide 1s ease-in-out infinite;
}

@keyframes loading-slide {
  from { transform: translateX(-110%); }
  to { transform: translateX(320%); }
}

.form-actions {
  display: flex;
  gap: 8px;
}

.form-actions button:last-child,
#refreshButton,
#arrivalButton,
button.secondary {
  background: transparent;
  color: var(--moss);
}

button:disabled {
  cursor: not-allowed;
  opacity: 0.48;
}

.hidden {
  display: none !important;
}

.task-list,
.slot-list {
  display: grid;
  gap: 10px;
}

.task {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 14px;
  padding: 14px;
  border: 1px solid var(--line);
  border-left: 5px solid var(--sage);
  border-radius: 8px;
  background: white;
}

.task[data-status="RUNNING"] {
  border-left-color: var(--clay);
}

.task[data-status="PAUSED"] {
  border-left-color: #b58a32;
}

.task[data-risk="HIGH"] {
  border-color: color-mix(in srgb, var(--clay), white 35%);
  border-left-color: var(--clay);
}

.task[data-status="COMPLETED"] {
  opacity: 0.72;
}

.task h3 {
  margin: 0 0 8px;
  font-size: 17px;
}

.task-main {
  min-width: 0;
  padding-left: min(calc(var(--depth, 0) * 22px), 132px);
}

.task-heading {
  display: flex;
  align-items: center;
  gap: 8px;
}

.tree-joint {
  flex: 0 0 auto;
  width: 10px;
  height: 10px;
  border-bottom: 1px solid var(--line);
  border-left: 1px solid var(--line);
}

.task-heading h3 {
  min-width: 0;
  overflow-wrap: anywhere;
}

.task-progress {
  width: min(320px, 100%);
  height: 5px;
  margin-top: 10px;
  overflow: hidden;
  border-radius: 3px;
  background: var(--line);
}

.task-progress span {
  display: block;
  height: 100%;
  background: var(--focus);
}

.progress-text {
  color: var(--focus);
  font-weight: 800;
}

.task-meta {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
  color: var(--steel);
  font-size: 12px;
}

.pill {
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--paper);
}

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

.task-actions button {
  min-width: 38px;
  padding: 0 10px;
}

.task-actions .check-button {
  width: 38px;
  min-width: 38px;
  padding: 0;
  border-color: var(--focus);
  background: var(--focus);
  font-size: 18px;
}

.task-actions button.secondary,
.filter-button {
  background: transparent;
  color: var(--moss);
}

.task-description,
.task-risk {
  margin: 8px 0 0;
  color: var(--steel);
  font-size: 12px;
  line-height: 1.45;
}

.task-risk {
  color: #8d402d;
  font-weight: 700;
}

.task-filters {
  display: flex;
  gap: 4px;
  margin-top: 10px;
}

.filter-button {
  min-height: 30px;
  border-color: var(--line);
  padding: 0 10px;
  font-size: 12px;
}

.filter-button.active {
  border-color: var(--moss);
  background: var(--moss);
  color: white;
}

.risk-panel {
  display: grid;
  grid-template-columns: 190px 1fr;
  gap: 20px;
  align-items: start;
  margin-bottom: 18px;
  border-top: 2px solid var(--clay);
  border-bottom: 1px solid var(--line);
  padding: 14px 2px;
}

.risk-panel h2 {
  margin-top: 4px;
}

.risk-list {
  display: flex;
  flex-wrap: wrap;
  gap: 8px;
}

.risk-item {
  display: grid;
  min-width: 210px;
  grid-template-columns: 1fr auto;
  gap: 4px 12px;
  border-left: 3px solid var(--clay);
  background: white;
  color: var(--ink);
  text-align: left;
  padding: 9px 12px;
}

.empty-state {
  border: 1px dashed var(--line);
  color: var(--steel);
  padding: 22px;
  text-align: center;
}

.risk-item span {
  grid-column: 1 / -1;
  color: var(--steel);
  font-size: 11px;
}

.event-list {
  display: grid;
  gap: 0;
  max-height: 480px;
  margin: 0;
  padding: 0;
  overflow: auto;
  list-style: none;
}

.event-list li {
  position: relative;
  padding: 0 0 16px 24px;
  border-left: 2px solid var(--line);
}

.event-list li::before {
  content: "";
  position: absolute;
  left: -6px;
  top: 2px;
  width: 10px;
  height: 10px;
  border-radius: 50%;
  background: var(--clay);
}

.event-type {
  display: block;
  font-weight: 800;
}

.event-time {
  color: var(--steel);
  font-size: 12px;
}

.slot {
  display: grid;
  grid-template-columns: auto 1fr auto;
  gap: 12px;
  align-items: center;
  padding: 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: white;
}

.slot-index {
  display: grid;
  width: 36px;
  height: 36px;
  place-items: center;
  border-radius: 6px;
  background: var(--moss);
  color: white;
  font-weight: 800;
}

.slots-panel,
.calendar-panel,
.history-panel {
  margin-top: 18px;
}

.history-toolbar {
  display: grid;
  grid-template-columns: minmax(160px, 220px) minmax(160px, 220px) auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 14px;
}

.history-loading {
  display: grid;
  gap: 8px;
}

.history-loading span {
  height: 44px;
  border-radius: 6px;
  background: linear-gradient(90deg, var(--paper), white, var(--paper));
  background-size: 200% 100%;
  animation: history-pulse 1.2s linear infinite;
}

@keyframes history-pulse {
  to { background-position: -200% 0; }
}

.history-result {
  display: grid;
  gap: 0;
}

.history-result article {
  display: flex;
  justify-content: space-between;
  gap: 16px;
  border-bottom: 1px solid var(--line);
  padding: 12px 2px;
}

.history-result article span,
.history-source {
  color: var(--steel);
  font-size: 12px;
}

.history-source {
  border-left: 3px solid var(--focus);
  padding: 7px 10px;
  font-weight: 700;
}

.calendar-title,
.calendar-actions,
.calendar-title > div {
  display: flex;
  align-items: center;
}

.calendar-title {
  gap: 12px;
}

.calendar-title > div {
  align-items: flex-start;
  flex-direction: column;
  gap: 3px;
}

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

.google-mark {
  display: grid;
  width: 36px;
  height: 36px;
  grid-template-columns: repeat(2, 1fr);
  overflow: hidden;
  border-radius: 6px;
}

.google-mark i:nth-child(1) { background: #4285f4; }
.google-mark i:nth-child(2) { background: #ea4335; }
.google-mark i:nth-child(3) { background: #fbbc04; }
.google-mark i:nth-child(4) { background: #34a853; }

.calendar-layout {
  display: grid;
  grid-template-columns: minmax(260px, 0.7fr) minmax(0, 1.3fr);
  gap: 24px;
  border-top: 1px solid var(--line);
  padding-top: 18px;
}

.calendar-status {
  border-right: 1px solid var(--line);
  padding-right: 24px;
}

.calendar-status > strong {
  display: block;
  margin-top: 12px;
  font-size: 18px;
}

.calendar-detail {
  min-height: 40px;
  margin: 8px 0 18px;
  color: var(--steel);
  font-size: 13px;
  line-height: 1.5;
}

.connection-badge {
  display: inline-flex;
  border: 1px solid var(--line);
  border-radius: 999px;
  padding: 4px 8px;
  background: var(--paper);
  color: var(--steel);
  font-size: 12px;
  font-weight: 800;
}

.connection-badge[data-state="connected"] {
  border-color: #34a853;
  color: #1f6e37;
}

.connection-badge[data-state="ready"] {
  border-color: #4285f4;
  color: #245fae;
}

.calendar-facts {
  display: grid;
  gap: 9px;
  margin: 0;
}

.calendar-facts div {
  display: grid;
  grid-template-columns: 110px 1fr;
  gap: 10px;
}

.calendar-facts dt,
.calendar-facts dd {
  margin: 0;
  font-size: 12px;
}

.calendar-facts dt {
  color: var(--steel);
}

.calendar-facts dd {
  overflow-wrap: anywhere;
  font-weight: 700;
}

.google-event-list {
  display: grid;
  align-content: start;
  margin: 0;
  padding: 0;
  list-style: none;
}

.google-event,
.calendar-empty {
  display: grid;
  grid-template-columns: 130px 1fr auto;
  gap: 14px;
  align-items: center;
  min-height: 54px;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.google-event:last-child,
.calendar-empty:last-child {
  border-bottom: 0;
}

.google-event time,
.google-event span,
.calendar-empty span {
  color: var(--steel);
  font-size: 12px;
}

.google-event div {
  display: grid;
  gap: 4px;
}

.calendar-empty {
  grid-template-columns: 1fr;
  place-content: center;
  text-align: center;
}

.notice {
  position: fixed;
  right: 20px;
  bottom: 20px;
  z-index: 10;
  max-width: min(380px, calc(100vw - 40px));
  border: 1px solid var(--moss);
  border-radius: 6px;
  background: var(--moss);
  color: white;
  padding: 12px 16px;
  box-shadow: 0 12px 32px rgba(38, 54, 47, 0.2);
  font-size: 13px;
  font-weight: 700;
}

.notice[data-kind="error"] {
  border-color: var(--clay);
  background: var(--clay);
}

.action-dialog {
  width: min(680px, calc(100vw - 32px));
  max-height: min(720px, calc(100vh - 32px));
  overflow: auto;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  color: var(--ink);
  padding: 20px;
  box-shadow: 0 24px 70px rgba(24, 35, 31, 0.25);
}

.action-dialog::backdrop {
  background: rgba(24, 35, 31, 0.55);
}

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

.dialog-head {
  display: flex;
  align-items: start;
  justify-content: space-between;
  gap: 20px;
  margin-bottom: 18px;
}

.dialog-head h2 {
  margin-top: 5px;
  font-size: 22px;
}

.icon-button {
  width: 38px;
  padding: 0;
  font-size: 22px;
}

.candidate-list {
  display: grid;
  gap: 8px;
}

.candidate {
  display: grid;
  grid-template-columns: 1fr auto;
  gap: 6px 14px;
  align-items: center;
  border-top: 1px solid var(--line);
  padding: 12px 0;
}

.candidate p {
  margin: 0;
  color: var(--steel);
  font-size: 12px;
}

.candidate-score {
  color: var(--clay);
  font-weight: 800;
}

.dialog-actions {
  justify-content: flex-end;
  margin-top: 18px;
}

.auth-view {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 28px;
}

.auth-sheet {
  display: grid;
  width: min(900px, 100%);
  grid-template-columns: minmax(0, 1fr) minmax(320px, 0.8fr);
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 20px 60px rgba(38, 54, 47, 0.14);
}

.auth-identity {
  display: flex;
  min-height: 500px;
  flex-direction: column;
  background: var(--moss);
  color: white;
  padding: 34px;
}

.auth-identity .mark {
  border-color: white;
  color: white;
}

.auth-identity .eyebrow {
  margin-top: 54px;
  color: #b8c7bf;
}

.auth-identity h1 {
  max-width: 480px;
  margin-top: 12px;
  font-size: 42px;
}

.auth-ledger {
  display: grid;
  margin-top: auto;
}

.auth-ledger span {
  border-top: 1px solid rgba(255, 255, 255, 0.24);
  padding: 9px 0;
  color: #dce5df;
  font-size: 12px;
}

.auth-form {
  display: grid;
  align-content: center;
  gap: 18px;
  padding: 42px;
}

.auth-form h2 {
  margin-top: 7px;
  font-size: 24px;
}

.auth-form button[type="submit"] {
  margin-top: 4px;
}

.auth-error {
  margin: 0;
  border-left: 3px solid var(--clay);
  color: #8d402d;
  padding-left: 10px;
  font-size: 13px;
  line-height: 1.4;
}

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

  .rail {
    position: static;
    display: flex;
    flex-direction: row;
    flex-wrap: wrap;
    width: 100%;
    height: auto;
    align-items: center;
    justify-content: space-between;
  }

  nav {
    grid-auto-flow: column;
    margin-top: 0;
  }

  .rail-account {
    display: grid;
    width: 100%;
    grid-template-columns: 1fr auto;
    align-items: center;
    margin-top: 12px;
    padding-top: 10px;
  }

  .rail-account span {
    display: none;
  }

  .rail-account button {
    grid-column: 2;
    grid-row: 1;
    margin-top: 0;
  }

  main {
    padding: 20px;
  }

  .status-grid,
  .workspace,
  .task-form,
  .calendar-layout,
  .history-toolbar {
    grid-template-columns: 1fr;
  }

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

  .task-form .wide-field {
    grid-column: auto;
  }

  .risk-panel {
    grid-template-columns: 1fr;
  }

  .task {
    grid-template-columns: 1fr;
  }

  .task-main {
    padding-left: min(calc(var(--depth, 0) * 14px), 70px);
  }

  .calendar-status {
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 0 0 18px;
  }

  .google-event {
    grid-template-columns: 1fr auto;
  }

  .google-event time {
    grid-column: 1 / -1;
  }

  .auth-view {
    align-items: start;
    padding: 16px;
  }

  .auth-sheet {
    grid-template-columns: 1fr;
  }

  .auth-identity {
    min-height: 270px;
    padding: 24px;
  }

  .auth-identity .eyebrow {
    margin-top: 30px;
  }

  .auth-identity h1 {
    font-size: 32px;
  }

  .auth-ledger {
    grid-template-columns: repeat(3, 1fr);
    gap: 12px;
  }

  .auth-form {
    padding: 26px 24px 30px;
  }
}

@media (max-width: 560px) {
  main {
    padding: 16px;
  }

  h1 {
    font-size: 30px;
  }

  .topbar {
    align-items: center;
  }

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

  .status-grid strong {
    font-size: 24px;
  }

  .panel-head {
    align-items: flex-start;
  }

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

  .slot {
    grid-template-columns: auto 1fr;
  }

  .slot > .pill {
    display: none;
  }
}
