:root {
  --bg: #f4f5f7;
  --surface: #ffffff;
  --surface2: #f0f1f3;
  --border: #e2e4e9;
  --border-hover: #c9cdd5;
  --text: #1a1d27;
  --muted: #6b7280;
  --accent: #3b82f6;
  --accent-hover: #2563eb;
  --green: #16a34a;
  --green-bg: #dcfce7;
  --yellow: #ca8a04;
  --yellow-bg: #fef9c3;
  --red: #dc2626;
  --red-bg: #fee2e2;
  --blue: #2563eb;
  --blue-bg: #dbeafe;
  --purple: #7c3aed;
  --purple-bg: #ede9fe;
  --orange: #ea580c;
  --orange-bg: #ffedd5;
}
* { margin: 0; padding: 0; box-sizing: border-box; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg);
  color: var(--text);
  min-height: 100vh;
}
a { color: var(--accent); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Brand */
.brand {
  text-transform: lowercase;
  font-size: 0.85em;
  letter-spacing: 0.5px;
  color: var(--accent) !important;
  text-decoration: none !important;
}

/* Header */
.header {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  box-shadow: 0 1px 4px rgba(0,0,0,0.05);
  padding: 14px 32px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  position: sticky;
  top: 0;
  z-index: 100;
}
.header h1 { font-size: 20px; font-weight: 700; }
.header h1 a { color: var(--text); text-decoration: none; }
.header-right { display: flex; align-items: center; gap: 12px; }
.header-right .user { color: var(--muted); font-size: 13px; }

/* Buttons */
.btn {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 16px;
  border-radius: 8px;
  font-size: 13px;
  font-weight: 500;
  cursor: pointer;
  border: 1px solid var(--border);
  transition: all 0.2s;
  text-decoration: none;
  color: var(--text);
  background: var(--surface);
}
.btn:hover { border-color: var(--muted); text-decoration: none; }
.btn-primary { background: var(--accent); color: #fff; border-color: var(--accent); }
.btn-primary:hover { background: var(--accent-hover); }
.btn-danger { color: var(--red); }
.btn-danger:hover { background: var(--red-bg); border-color: var(--red); }
.btn-sm { padding: 5px 10px; font-size: 12px; }
.btn-ghost { background: transparent; border-color: transparent; }
.btn-ghost:hover { background: var(--surface2); border-color: var(--border); }

/* Badges */
.badge {
  display: inline-block;
  padding: 3px 10px;
  border-radius: 6px;
  font-size: 11px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.3px;
  white-space: nowrap;
}
.badge.live { background: var(--green-bg); color: var(--green); }
.badge.in_progress { background: var(--yellow-bg); color: var(--yellow); }
.badge.degraded { background: var(--red-bg); color: var(--red); }
.badge.tier1 { background: var(--red-bg); color: var(--red); }
.badge.tier2 { background: var(--blue-bg); color: var(--blue); }
.badge.tier3 { background: var(--purple-bg); color: var(--purple); }
.badge.high { background: var(--orange-bg); color: var(--orange); }

/* Stats bar */
.stats {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(150px, 1fr));
  gap: 14px;
  padding: 24px 32px;
  max-width: 1400px;
  margin: 0 auto;
}
.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.stat-card .label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  margin-bottom: 4px;
}
.stat-card .value { font-size: 30px; font-weight: 700; }
.stat-card.live .value { color: var(--green); }
.stat-card.progress .value { color: var(--yellow); }
.stat-card.degraded .value { color: var(--red); }
.stat-card.tasks .value { color: var(--accent); }

/* Forms */
.form-group { margin-bottom: 18px; }
.form-group label {
  display: block;
  font-size: 12px;
  font-weight: 500;
  color: var(--muted);
  margin-bottom: 6px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
}
.form-input, .form-select, .form-textarea {
  width: 100%;
  padding: 10px 14px;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: 8px;
  color: var(--text);
  font-size: 14px;
  outline: none;
  transition: border-color 0.2s;
  font-family: inherit;
}
.form-input:focus, .form-select:focus, .form-textarea:focus { border-color: var(--accent); }
.form-textarea { min-height: 80px; resize: vertical; }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 16px; }
.form-inline {
  display: flex;
  gap: 8px;
}
.form-inline .form-input { flex: 1; }

/* Container */
.container {
  max-width: 1400px;
  margin: 0 auto;
  padding: 0 32px;
}

/* Grid */
.grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(380px, 1fr));
  gap: 16px;
  padding-bottom: 48px;
}

/* Cards */
.card {
  background: var(--surface);
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  transition: border-color 0.2s, transform 0.15s;
  display: flex;
  flex-direction: column;
}
.card:hover { border-color: var(--border-hover); }
.card-clickable { cursor: pointer; }
.card-clickable:hover { transform: translateY(-2px); border-color: var(--accent); }
.card-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 8px;
}
.card-title { font-size: 17px; font-weight: 700; letter-spacing: -0.3px; }
.card-title a { color: var(--text); }
.card-title a:hover { color: var(--accent); text-decoration: none; }
.badges { display: flex; gap: 6px; flex-shrink: 0; }
.card-desc {
  color: var(--muted);
  font-size: 13px;
  line-height: 1.5;
  margin-bottom: 12px;
}
.card-meta {
  display: flex;
  gap: 14px;
  font-size: 12px;
  color: var(--muted);
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.card-progress {
  margin-top: auto;
  border-top: 1px solid var(--border);
  padding-top: 12px;
}
.progress-bar-bg {
  height: 6px;
  background: var(--bg);
  border-radius: 3px;
  overflow: hidden;
  margin-top: 6px;
}
.progress-bar-fill {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  transition: width 0.3s;
}
.progress-text {
  display: flex;
  justify-content: space-between;
  font-size: 12px;
  color: var(--muted);
}

/* Filters */
.toolbar {
  padding: 0 0 16px;
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  align-items: center;
  justify-content: space-between;
}
.filters { display: flex; gap: 6px; flex-wrap: wrap; }
.filter-btn {
  padding: 6px 14px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 20px;
  color: var(--muted);
  font-size: 12px;
  cursor: pointer;
  transition: all 0.2s;
}
.filter-btn:hover { color: var(--text); border-color: var(--muted); }
.filter-btn.active { background: var(--accent); color: #fff; border-color: var(--accent); }

/* Task list */
.task-list { list-style: none; }
.task-item {
  display: flex;
  flex-direction: column;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  font-size: 14px;
}
.task-item:last-child { border-bottom: none; }
.task-item.task-done .task-title { text-decoration: line-through; color: var(--muted); }
.task-item.task-active { background: var(--green-bg); margin: 0 -12px; padding: 10px 12px; border-radius: 8px; }

/* Status dots */
.task-status-dot {
  width: 10px;
  height: 10px;
  border-radius: 50%;
  flex-shrink: 0;
}
.task-status-dot.pending { background: var(--border-hover); }
.task-status-dot.active { background: var(--green); animation: pulse 2s infinite; }
.task-status-dot.done { background: var(--muted); }

@keyframes pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.4; }
}

/* Task action buttons */
.task-btn-start {
  background: var(--green-bg) !important;
  color: var(--green) !important;
  border-color: var(--green) !important;
  font-weight: 600;
}
.task-btn-start:hover { background: var(--green) !important; color: #fff !important; }
.task-btn-complete {
  background: var(--green) !important;
  color: #fff !important;
  border-color: var(--green) !important;
  font-weight: 600;
}
.task-btn-complete:hover { opacity: 0.9; }

/* Active badge */
.task-active-badge { background: var(--green-bg); color: var(--green); font-variant-numeric: tabular-nums; }

/* Task row + progress */
.task-row {
  display: flex;
  align-items: center;
  gap: 10px;
  width: 100%;
}
.task-progress-row {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-top: 6px;
  padding-left: 20px;
  width: 100%;
}
.task-progress-bar-bg {
  flex: 1;
  height: 5px;
  background: var(--border);
  border-radius: 3px;
  overflow: hidden;
}
.task-progress-bar-fill {
  height: 100%;
  background: var(--green);
  border-radius: 3px;
  transition: width 0.3s;
}
.task-progress-btns {
  display: flex;
  gap: 3px;
  flex-shrink: 0;
}
.progress-pip {
  padding: 2px 8px;
  font-size: 11px;
  font-weight: 500;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--surface);
  color: var(--muted);
  cursor: pointer;
  transition: all 0.15s;
}
.progress-pip:hover { border-color: var(--green); color: var(--green); }
.progress-pip.active { background: var(--green-bg); color: var(--green); border-color: var(--green); }

/* Project link in active tasks banner */
.task-project-link {
  font-weight: 600;
  font-size: 12px;
  color: var(--accent);
  background: var(--blue-bg);
  padding: 2px 8px;
  border-radius: 4px;
  flex-shrink: 0;
  text-decoration: none;
}
.task-project-link:hover { text-decoration: underline; }

/* Cost & API styles */
.stat-card.cost .value { color: var(--orange); }
.cost-tag {
  color: var(--orange);
  font-weight: 600;
}
.cost-total {
  font-size: 16px;
  font-weight: 700;
  color: var(--orange);
}
.api-count { color: var(--accent); }

.api-add-form {
  display: flex;
  gap: 8px;
  margin-bottom: 16px;
  flex-wrap: wrap;
}
.api-add-form .form-input { min-width: 0; }

.api-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}
.api-table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
  padding: 6px 10px;
  border-bottom: 2px solid var(--border);
}
.api-table td {
  padding: 10px;
  border-bottom: 1px solid var(--border);
  vertical-align: middle;
}
.api-table tr:last-child td { border-bottom: none; }
.api-table tr:hover { background: var(--surface2); }
.api-name { font-weight: 600; }
.api-cost { font-variant-numeric: tabular-nums; white-space: nowrap; }
.api-notes { color: var(--muted); font-size: 12px; }
.api-actions { width: 30px; text-align: right; }
.api-actions form { opacity: 0; transition: opacity 0.2s; }
.api-table tr:hover .api-actions form { opacity: 1; }

/* Active tasks banner */
.active-banner {
  background: var(--surface);
  border: 2px solid var(--green);
  border-radius: 14px;
  padding: 20px 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.task-title { flex: 1; }
.task-actions { display: flex; gap: 4px; opacity: 0; transition: opacity 0.2s; }
.task-item:hover .task-actions { opacity: 1; }

/* Comments */
.comment {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 14px 16px;
  margin-bottom: 10px;
}
.comment-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 6px;
}
.comment-author { font-size: 13px; font-weight: 600; }
.comment-date { font-size: 11px; color: var(--muted); }
.comment-text { font-size: 14px; line-height: 1.6; white-space: pre-wrap; }
.comment-actions { opacity: 0; transition: opacity 0.2s; }
.comment:hover .comment-actions { opacity: 1; }

/* Sections */
.section {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 24px;
  margin-bottom: 20px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.section-header {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
}
.section-title {
  font-size: 15px;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.5px;
  color: var(--muted);
}

/* Detail hero */
.project-hero {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 32px;
  margin-bottom: 24px;
  box-shadow: 0 1px 3px rgba(0,0,0,0.06);
}
.project-hero-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  margin-bottom: 12px;
}
.project-hero h2 { font-size: 28px; font-weight: 700; letter-spacing: -0.5px; }
.project-hero .desc { color: var(--muted); font-size: 15px; line-height: 1.6; margin-bottom: 16px; }
.meta-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
  gap: 12px;
}
.meta-item {
  background: var(--bg);
  border-radius: 8px;
  padding: 10px 14px;
}
.meta-item .meta-label { font-size: 11px; color: var(--muted); text-transform: uppercase; letter-spacing: 0.5px; }
.meta-item .meta-value { font-size: 14px; font-weight: 500; margin-top: 2px; }
.hero-actions { display: flex; gap: 8px; }

/* Two column layout */
.two-col {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 20px;
  padding-bottom: 48px;
}

/* Back link */
.back-link {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  color: var(--muted);
  font-size: 13px;
  margin-bottom: 20px;
  padding: 24px 0 0;
}
.back-link:hover { color: var(--text); text-decoration: none; }

/* Email styles */
.email-accounts-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(350px, 1fr));
  gap: 14px;
}
.email-account-card {
  background: var(--surface2);
  border: 1px solid var(--border);
  border-radius: 12px;
  padding: 18px;
}
.email-account-top {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  gap: 12px;
}
.email-account-label { font-size: 16px; font-weight: 600; }
.email-account-addr { font-size: 13px; color: var(--accent); }
.email-account-actions { display: flex; gap: 6px; flex-shrink: 0; }
.email-account-features {
  display: flex;
  gap: 6px;
  margin-top: 12px;
  padding-top: 12px;
  border-top: 1px solid var(--border);
}
.date-range-form { margin-top: 16px; }
.date-range-row {
  display: flex;
  gap: 12px;
  align-items: end;
  flex-wrap: wrap;
}
.date-range-row .form-group { min-width: 140px; }

.email-list {}
.email-item {
  border-bottom: 1px solid var(--border);
  padding: 12px 0;
  cursor: pointer;
  transition: background 0.15s;
}
.email-item:last-child { border-bottom: none; }
.email-item:hover { background: var(--surface2); margin: 0 -12px; padding: 12px 12px; border-radius: 8px; }
.email-row {
  display: grid;
  grid-template-columns: 180px 1fr 120px;
  gap: 12px;
  align-items: center;
}
.email-from {
  font-size: 13px;
  font-weight: 600;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.email-subject {
  font-size: 14px;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.email-date {
  font-size: 12px;
  color: var(--muted);
  text-align: right;
  white-space: nowrap;
}
.email-body {
  display: none;
  margin-top: 10px;
  padding: 12px;
  background: var(--bg);
  border-radius: 8px;
  font-size: 13px;
  line-height: 1.6;
  color: var(--muted);
  white-space: pre-wrap;
  word-break: break-word;
}
.email-body.open { display: block; }

/* Status alert button in header */
.btn-status-alert {
  background: var(--red) !important;
  color: #fff !important;
  border-color: var(--red) !important;
  animation: pulse-alert 2s infinite;
}
@keyframes pulse-alert {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}

/* Health status strip */
.status-strip {
  background: var(--surface);
  border-bottom: 1px solid var(--border);
}
.status-strip-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 4px 32px;
  display: flex;
  align-items: center;
  gap: 18px;
  font-size: 11px;
  color: var(--muted);
  text-decoration: none !important;
}
.status-strip-inner:hover { background: var(--surface2); }
.status-item {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  font-weight: 500;
}
.status-dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  flex-shrink: 0;
}
.status-item.ok .status-dot { background: var(--green); }
.status-item.warn .status-dot { background: var(--yellow); }
.status-item.err .status-dot { background: var(--red); }
.status-item.ok { color: var(--green); }
.status-item.warn { color: var(--yellow); }
.status-item.err { color: var(--red); }
.status-ts { margin-left: auto; font-size: 10px; color: var(--muted); }

/* Alerts banner */
.alerts-banner {
  background: var(--red);
  color: #fff;
}
.alerts-inner {
  max-width: 1400px;
  margin: 0 auto;
  padding: 10px 32px;
}
.alerts-header {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 13px;
  margin-bottom: 6px;
}
.alerts-icon { font-size: 16px; }
.alerts-list {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
}
.alert-chip {
  display: inline-flex;
  align-items: center;
  gap: 4px;
  background: rgba(255,255,255,0.15);
  padding: 3px 10px;
  border-radius: 4px;
  font-size: 11px;
  font-weight: 500;
}
.alert-type {
  text-transform: uppercase;
  font-size: 9px;
  font-weight: 700;
  background: rgba(255,255,255,0.25);
  padding: 1px 4px;
  border-radius: 2px;
  letter-spacing: 0.5px;
}

/* Responsive */
@media (max-width: 900px) {
  .two-col { grid-template-columns: 1fr; }
  .form-row { grid-template-columns: 1fr; }
}
@media (max-width: 768px) {
  .header { padding: 12px 16px; }
  .container { padding: 0 16px; }
  .stats { padding: 16px; gap: 10px; grid-template-columns: repeat(2, 1fr); }
  .grid { grid-template-columns: 1fr; }
  .stat-card .value { font-size: 24px; }
  .project-hero { padding: 20px; }
  .project-hero h2 { font-size: 22px; }
  .toolbar { flex-direction: column; align-items: stretch; }
}

/* Modal */
.modal-backdrop {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.6);
  z-index: 200;
  align-items: center;
  justify-content: center;
}
.modal-backdrop.open { display: flex; }
.modal {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 32px;
  width: 90%;
  max-width: 500px;
  max-height: 90vh;
  overflow-y: auto;
}
.modal h3 { font-size: 18px; margin-bottom: 20px; }
