:root {
  --bg: #f3f5f6;
  --surface: #ffffff;
  --surface-muted: #eef1f2;
  --ink: #171b1d;
  --muted: #667077;
  --line: #d7dddf;
  --brand: #176b57;
  --brand-dark: #0f4f40;
  --blue: #285e9b;
  --danger: #a33a3a;
  --danger-bg: #fff0ee;
  --warning: #8a5d0a;
  --success-bg: #e9f6f1;
  --shadow: 0 12px 32px rgba(26, 35, 39, 0.08);
}

* { box-sizing: border-box; }

html { min-width: 320px; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--ink);
  font-family: Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", "PingFang SC", sans-serif;
  font-size: 14px;
  letter-spacing: 0;
}

button, input, select { font: inherit; letter-spacing: 0; }

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

.app-header {
  background: #14191b;
  color: #f8faf9;
  border-bottom: 3px solid var(--brand);
}

.header-inner {
  width: min(1180px, calc(100% - 40px));
  min-height: 82px;
  margin: 0 auto;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 24px;
}

.brand-lockup { display: flex; align-items: center; gap: 13px; min-width: 0; }
.brand-lockup h1 { margin: 2px 0 0; font-size: 19px; line-height: 1.2; font-weight: 680; }

.brand-mark {
  width: 48px;
  height: 48px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 6px;
  background: var(--brand);
  color: #fff;
  font-weight: 800;
  font-size: 16px;
}

.brand-mark-small { width: 42px; height: 42px; }

.eyebrow, .section-kicker {
  margin: 0;
  color: #91aaa2;
  font-size: 10px;
  font-weight: 750;
  text-transform: uppercase;
}

.section-kicker { color: var(--brand); }

.app-main { width: min(1180px, calc(100% - 40px)); margin: 28px auto 48px; }

.flash-stack { display: grid; gap: 8px; margin-bottom: 18px; }
.flash { padding: 11px 13px; border: 1px solid; border-radius: 5px; }
.flash-success { color: var(--brand-dark); background: var(--success-bg); border-color: #9bcbbd; }
.flash-error { color: #7f2626; background: var(--danger-bg); border-color: #e2aaaa; }

.status-band {
  display: grid;
  grid-template-columns: 180px minmax(0, 1fr) auto;
  gap: 24px;
  align-items: center;
  padding: 21px 0 24px;
  border-top: 1px solid var(--line);
  border-bottom: 1px solid var(--line);
}

h2 { margin: 4px 0 0; font-size: 18px; line-height: 1.25; font-weight: 700; }

.status-metrics { display: grid; grid-template-columns: 110px 90px minmax(180px, 1fr); gap: 18px; }
.metric { min-width: 0; }
.metric span { display: block; margin-bottom: 6px; color: var(--muted); font-size: 12px; }
.metric strong { display: block; overflow-wrap: anywhere; }

.status-pill {
  width: fit-content;
  min-width: 72px;
  padding: 5px 9px;
  border: 1px solid;
  border-radius: 999px;
  text-align: center;
  font-size: 12px;
}

.status-running { color: var(--brand-dark); background: var(--success-bg); border-color: #95c8b9; }
.status-stopped { color: #697277; background: #f0f2f3; border-color: #cbd1d4; }
.text-success { color: var(--brand-dark); }
.text-warning { color: var(--warning); }

.action-row { display: flex; gap: 8px; align-items: center; }
.action-row form { margin: 0; }

.button {
  min-height: 36px;
  padding: 8px 14px;
  border: 1px solid transparent;
  border-radius: 5px;
  background: var(--surface);
  color: var(--ink);
  font-weight: 650;
  white-space: nowrap;
}

.button-primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.button-primary:hover:not(:disabled) { background: var(--brand-dark); }
.button-secondary { border-color: #aeb8bc; background: var(--surface); }
.button-secondary:hover:not(:disabled) { background: var(--surface-muted); }
.button-danger { border-color: var(--danger); background: var(--danger); color: #fff; }
.button-quiet { color: #e9efed; border-color: #596467; background: transparent; }
.button-wide { width: 100%; }
.button-compact { min-height: 31px; padding: 5px 10px; }
.button-link-danger { min-height: auto; padding: 0; border: 0; color: var(--danger); background: transparent; }

.workspace-grid {
  display: grid;
  grid-template-columns: minmax(0, 1.65fr) minmax(300px, 0.85fr);
  gap: 22px;
  margin-top: 24px;
  align-items: start;
}

.side-stack { display: grid; gap: 22px; min-width: 0; }

.tool-panel, .log-panel {
  background: var(--surface);
  border: 1px solid var(--line);
  border-radius: 6px;
  box-shadow: var(--shadow);
}

.tool-panel { padding: 20px; }
.section-heading { display: flex; justify-content: space-between; align-items: flex-start; gap: 18px; margin-bottom: 20px; }
.save-state, .log-actions span { color: var(--muted); font-size: 12px; }

.form-grid { display: grid; grid-template-columns: minmax(0, 1fr) 140px 140px; gap: 16px; }
.field { min-width: 0; }
.field-span { grid-column: 1 / -1; }
.field label:not(.check-row) { display: block; margin-bottom: 6px; color: #3e484d; font-size: 12px; font-weight: 650; }
.field label span { color: var(--muted); font-weight: 500; }

input[type="text"], input[type="password"], input[type="url"], input[type="number"], select, .login-form input {
  width: 100%;
  min-height: 39px;
  padding: 8px 10px;
  border: 1px solid #b8c1c4;
  border-radius: 4px;
  background: #fff;
  color: var(--ink);
  outline: none;
}

input:focus, select:focus { border-color: var(--blue); box-shadow: 0 0 0 3px rgba(40, 94, 155, 0.12); }

.toggle-row, .check-row { display: flex; align-items: center; gap: 9px; color: #3e484d; }
.toggle-row input { position: absolute; opacity: 0; pointer-events: none; }
.toggle { width: 34px; height: 19px; border-radius: 999px; background: #b7bec1; position: relative; transition: background 150ms ease; }
.toggle::after { content: ""; width: 13px; height: 13px; position: absolute; top: 3px; left: 3px; border-radius: 50%; background: #fff; transition: transform 150ms ease; }
.toggle-row input:checked + .toggle { background: var(--brand); }
.toggle-row input:checked + .toggle::after { transform: translateX(15px); }
.check-row { margin-top: 7px; font-size: 12px; color: var(--muted); }

.provider-fields { display: none; grid-template-columns: 1fr 1fr; gap: 14px; padding: 14px; background: var(--surface-muted); border: 1px solid var(--line); border-radius: 5px; }
.provider-fields.is-active { display: grid; }
.form-actions { display: flex; justify-content: flex-end; padding-top: 2px; }

.upload-form { display: grid; gap: 10px; }
.file-picker { min-height: 84px; display: grid; place-items: center; padding: 12px; border: 1px dashed #9da9ad; border-radius: 5px; background: var(--surface-muted); color: #465156; text-align: center; cursor: pointer; overflow-wrap: anywhere; }
.file-picker:hover { border-color: var(--brand); color: var(--brand-dark); }
.file-picker input { position: absolute; width: 1px; height: 1px; opacity: 0; }
.delete-row { margin-top: 15px; padding-top: 14px; border-top: 1px solid var(--line); text-align: right; }

.account-stats { display: grid; grid-template-columns: repeat(3, 1fr); gap: 1px; margin-bottom: 14px; border: 1px solid var(--line); background: var(--line); }
.account-stat { padding: 13px; background: var(--surface-muted); }
.account-stat span, .account-latest span { display: block; color: var(--muted); font-size: 12px; }
.account-stat strong { display: block; margin-top: 5px; font-size: 22px; line-height: 1; }
.account-latest { min-width: 0; margin-bottom: 16px; }
.account-latest strong { display: block; margin-top: 5px; overflow-wrap: anywhere; font: 12px/1.5 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; }
.export-controls { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 7px 8px; align-items: end; }
.export-controls label { color: #3e484d; font-size: 12px; font-weight: 650; }
.export-controls select { min-width: 0; }
.export-controls .button { width: auto; min-height: 39px; display: inline-grid; place-items: center; text-decoration: none; }

.log-panel { margin-top: 22px; padding: 20px; }
.log-actions { display: flex; align-items: center; gap: 10px; }
#log-output { min-height: 260px; max-height: 520px; margin: 0; padding: 15px; overflow: auto; border: 1px solid #2c3437; border-radius: 5px; background: #171c1e; color: #dce7e3; font: 12px/1.65 ui-monospace, SFMono-Regular, Menlo, Consolas, monospace; white-space: pre-wrap; overflow-wrap: anywhere; }

.login-shell { min-height: 100vh; display: grid; place-items: center; padding: 28px; background: #151a1c; border-top: 4px solid var(--brand); }
.login-panel { width: min(390px, 100%); padding: 30px; border-radius: 6px; background: var(--surface); box-shadow: 0 28px 80px rgba(0, 0, 0, 0.28); }
.login-panel .eyebrow { margin-top: 20px; color: var(--brand); }
.login-panel h1 { margin: 7px 0 25px; font-size: 24px; line-height: 1.25; }
.login-form { display: grid; gap: 12px; }
.login-form label { color: #3e484d; font-size: 12px; font-weight: 650; }

@media (max-width: 880px) {
  .status-band { grid-template-columns: 1fr; gap: 18px; }
  .status-metrics { grid-template-columns: 100px 80px minmax(0, 1fr); }
  .action-row { justify-content: flex-start; }
  .workspace-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: minmax(0, 1fr) 140px; }
}

@media (max-width: 560px) {
  .header-inner, .app-main { width: min(100% - 24px, 1180px); }
  .header-inner { min-height: 72px; gap: 12px; }
  .brand-mark-small { display: none; }
  .brand-lockup h1 { font-size: 16px; }
  .app-main { margin-top: 18px; }
  .status-metrics { grid-template-columns: 1fr 1fr; }
  .metric-wide { grid-column: 1 / -1; }
  .action-row { display: grid; grid-template-columns: repeat(3, 1fr); }
  .action-row .button { width: 100%; padding-inline: 8px; }
  .form-grid, .provider-fields { grid-template-columns: 1fr; }
  .field, .field-span { grid-column: 1; }
  .tool-panel, .log-panel { padding: 16px; }
  .export-controls { grid-template-columns: 1fr; }
  .export-controls .button { width: 100%; }
  .section-heading { align-items: center; }
  .log-panel .section-heading { align-items: flex-start; }
  .log-actions { flex-direction: column; align-items: flex-end; }
  #log-output { min-height: 300px; }
}
