:root {
  --navy: #0b1e3d;
  --navy-light: #14284d;
  --navy-border: #223a63;
  --teal: #0f8a82;
  --teal-dark: #0b6f68;
  --bg: #faf8f4;
  --surface: #ffffff;
  --text: #1c2430;
  --muted: #6b7280;
  --border: #e5e1d8;
  --danger: #b3261e;
  --danger-bg: #fbeae9;
  --warning: #92620a;
  --warning-bg: #fdf2df;
  --success: #146c43;
  --success-bg: #e8f5ee;
  --radius: 8px;
}

* { box-sizing: border-box; }
[hidden] { display: none !important; }

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
  background: var(--bg);
  color: var(--text);
  font-family: "Noto Sans TC", "Microsoft JhengHei", -apple-system, BlinkMacSystemFont, sans-serif;
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3 { line-height: 1.3; margin: 0 0 12px; }
h1 { font-size: 22px; }
h2 { font-size: 16px; }

.sr-only {
  position: absolute;
  width: 1px; height: 1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

/* ---------- Toast ---------- */
.toast-region {
  position: fixed;
  top: 12px;
  right: 12px;
  z-index: 500;
  display: flex;
  flex-direction: column;
  gap: 8px;
}
.toast {
  background: var(--navy);
  color: #fff;
  padding: 10px 14px;
  border-radius: var(--radius);
  box-shadow: 0 4px 12px rgba(0,0,0,0.2);
  max-width: 320px;
  font-size: 14px;
}
.toast.toast-error { background: var(--danger); }
.toast.toast-success { background: var(--success); }

/* ---------- Auth screen ---------- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, var(--navy) 0%, var(--navy-light) 100%);
}
.auth-card {
  background: var(--surface);
  border-radius: 12px;
  padding: 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: 0 20px 60px rgba(0,0,0,0.25);
}
.auth-logo {
  display: block;
  height: 48px;
  margin: 0 auto 12px;
}
.auth-title {
  text-align: center;
  font-size: 18px;
  color: var(--navy);
  margin-bottom: 20px;
}
.auth-form h2 { color: var(--navy); }

.notice {
  background: var(--warning-bg);
  color: var(--warning);
  border: 1px solid #f0d9a8;
  border-radius: var(--radius);
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
}

/* ---------- Forms ---------- */
.field { margin-bottom: 14px; }
.field label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  margin-bottom: 4px;
  color: var(--navy);
}
input[type="text"],
input[type="email"],
input[type="password"],
input[type="search"],
input[type="number"],
input[type="datetime-local"],
select,
textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  font-size: 14px;
  font-family: inherit;
  background: var(--surface);
  color: var(--text);
}
textarea { resize: vertical; }
input:focus, select:focus, textarea:focus, button:focus {
  outline: 2px solid var(--teal);
  outline-offset: 1px;
}
.radio-row { display: flex; gap: 16px; }
.radio-label { font-weight: 400; display: flex; align-items: center; gap: 6px; }
.char-count { display: block; text-align: right; font-size: 12px; color: var(--muted); margin-top: 2px; }

.form-hint { font-size: 13px; color: var(--muted); margin: 0 0 12px; }
.form-error {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 13px;
  margin: 0 0 12px;
}
.status-line { font-size: 13px; color: var(--muted); min-height: 18px; margin: 4px 0 12px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  border: none;
  border-radius: var(--radius);
  padding: 9px 16px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
  font-family: inherit;
}
.btn-primary { background: var(--teal); color: #fff; }
.btn-primary:hover { background: var(--teal-dark); }
.btn-secondary { background: #eef1f5; color: var(--navy); }
.btn-secondary:hover { background: #e2e7ee; }
.btn-ghost { background: transparent; color: #fff; border: 1px solid rgba(255,255,255,0.4); }
.btn-ghost:hover { background: rgba(255,255,255,0.1); }
.btn-link { background: none; color: var(--teal-dark); text-decoration: underline; padding: 4px 0; }
.btn-danger { background: var(--danger); color: #fff; }
.btn-row { display: flex; gap: 10px; flex-wrap: wrap; margin-bottom: 8px; }
button:disabled { opacity: 0.55; cursor: not-allowed; }

/* ---------- App shell ---------- */
.app-shell { min-height: 100vh; display: flex; flex-direction: column; }

.topbar {
  background: var(--navy);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 8px 16px;
  height: 56px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}
.topbar-logo { height: 28px; }
.topbar-title { font-weight: 600; font-size: 15px; white-space: nowrap; }
.topbar-spacer { flex: 1; }
.usage-label {
  background: rgba(255,255,255,0.1);
  border: 1px solid rgba(255,255,255,0.2);
  border-radius: 999px;
  padding: 5px 12px;
  font-size: 12.5px;
  white-space: nowrap;
}
.topbar-user { font-size: 13px; opacity: 0.85; white-space: nowrap; }

.nav-toggle {
  display: none;
  background: none;
  border: none;
  cursor: pointer;
  padding: 6px;
}
.nav-toggle-bar, .nav-toggle-bar::before, .nav-toggle-bar::after {
  content: "";
  display: block;
  width: 20px;
  height: 2px;
  background: #fff;
  position: relative;
}
.nav-toggle-bar::before { top: -6px; }
.nav-toggle-bar::after { top: 4px; }

.shell-body { display: flex; flex: 1; min-height: 0; }

.sidebar {
  width: 220px;
  flex-shrink: 0;
  background: var(--navy-light);
  color: #fff;
  padding: 16px 0;
  display: flex;
  flex-direction: column;
  justify-content: space-between;
}
.nav-list { list-style: none; margin: 0; padding: 0; }
.nav-link {
  display: block;
  width: 100%;
  text-align: left;
  background: none;
  border: none;
  color: rgba(255,255,255,0.85);
  padding: 12px 20px;
  font-size: 14px;
  cursor: pointer;
  border-left: 3px solid transparent;
}
.nav-link:hover { background: rgba(255,255,255,0.06); }
.nav-link.active {
  background: rgba(15,138,130,0.18);
  border-left-color: var(--teal);
  color: #fff;
  font-weight: 600;
}
.sidebar-footer {
  font-size: 11.5px;
  color: rgba(255,255,255,0.55);
  padding: 12px 20px 4px;
  border-top: 1px solid rgba(255,255,255,0.1);
}
.sidebar-backdrop {
  display: none;
}

.main-content {
  flex: 1;
  padding: 24px;
  overflow-y: auto;
  min-width: 0;
}

.page { max-width: 900px; }

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 18px;
  margin-bottom: 20px;
}

.section-title { margin-top: 24px; }

.banner {
  border-radius: var(--radius);
  padding: 10px 14px;
  font-size: 13.5px;
  margin-bottom: 16px;
}
.banner-warning { background: var(--warning-bg); color: var(--warning); border: 1px solid #f0d9a8; }
.banner-error { background: var(--danger-bg); color: var(--danger); border: 1px solid #f0b8b3; }

/* ---------- Lists ---------- */
.kv-list { display: grid; grid-template-columns: max-content 1fr; gap: 4px 16px; margin: 0; font-size: 14px; }
.kv-list dt { color: var(--muted); }
.kv-list dd { margin: 0; }

.task-list, .doc-list, .reminder-list, .health-list, .incident-list, .audit-list, .blocked-list {
  list-style: none;
  margin: 0 0 20px;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 10px;
}

.list-item {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.list-item-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  flex-wrap: wrap;
  margin-bottom: 6px;
}
.list-item-title { font-weight: 600; }
.list-item-meta { font-size: 12.5px; color: var(--muted); }
.list-item-body { font-size: 13.5px; white-space: pre-wrap; word-break: break-word; }
.mt-8 { margin-top: 8px; }
.text-success { color: var(--success); }
.text-danger { color: var(--danger); }
.checkbox-label { display: flex; align-items: center; gap: 8px; font-weight: 400; }

.badge {
  display: inline-block;
  border-radius: 999px;
  padding: 2px 10px;
  font-size: 12px;
  font-weight: 600;
}
.badge-pending { background: #eef1f5; color: var(--navy); }
.badge-running { background: #e3f0fd; color: #1a5fb4; }
.badge-succeeded, .badge-healthy, .badge-done { background: var(--success-bg); color: var(--success); }
.badge-failed, .badge-degraded { background: var(--danger-bg); color: var(--danger); }
.badge-cancelled, .badge-unknown { background: #eef1f5; color: var(--muted); }

.blocked-list li {
  background: var(--danger-bg);
  color: var(--danger);
  border-radius: var(--radius);
  padding: 6px 10px;
  font-size: 13.5px;
  width: fit-content;
}

.readonly-block {
  white-space: pre-wrap;
  word-break: break-word;
  font-family: inherit;
  font-size: 14px;
  margin: 0;
}

.empty-state {
  color: var(--muted);
  font-size: 13.5px;
  padding: 16px;
  text-align: center;
  border: 1px dashed var(--border);
  border-radius: var(--radius);
}

.search-field { max-width: 320px; }

.invite-result { margin-top: 14px; }
.invite-row { display: flex; gap: 8px; }
.invite-row input { flex: 1; }

.table-wrap { overflow-x: auto; margin-bottom: 20px; }
.data-table { width: 100%; border-collapse: collapse; font-size: 13.5px; background: var(--surface); }
.data-table th, .data-table td { text-align: left; padding: 8px 10px; border-bottom: 1px solid var(--border); white-space: nowrap; }
.data-table th { color: var(--muted); font-weight: 600; background: #f4f2ec; }
.data-table td.limit-cell { white-space: normal; }
.inline-num { width: 90px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  .nav-toggle { display: inline-block; }
  .sidebar {
    position: fixed;
    top: 56px;
    bottom: 0;
    left: 0;
    z-index: 200;
    transform: translateX(-100%);
    transition: transform 0.2s ease;
    width: 240px;
  }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop {
    display: block;
    position: fixed;
    top: 56px;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.35);
    z-index: 150;
  }
  .topbar-title { display: none; }
  .usage-label { font-size: 11px; padding: 4px 8px; }
  .main-content { padding: 16px; }
}
