/* MontaraOS design system — single source of truth.
   Swap --brand below when the official Montara hex is confirmed.
   Everything else derives from the token aliases; never hardcode hex in views. */

:root {
  /* ---- Brand (Montara green) ---- */
  --brand:        #00674B;
  --brand-600:    #004f39;
  --brand-700:    #003a2a;
  --brand-100:    #e6f2ee;

  /* ---- Semantic aliases (use these, not --brand directly) ---- */
  --accent:       var(--brand);
  --accent-hover: var(--brand-600);
  --accent-soft:  var(--brand-100);

  /* ---- Surfaces ---- */
  --bg:        #f8f8f6;
  --surface:   #ffffff;
  --surface-2: #f8f8f6;
  --border:    #e5e5e5;
  --overlay:   rgba(26, 26, 26, 0.45);

  /* ---- Text ---- */
  --text:        #1a1a1a;
  --text-muted:  #6b6b6b;
  --text-invert: #ffffff;

  /* ---- Status ---- */
  --success: #00674B;
  --warning: #c77700;
  --danger:  #BD1F2E;
  --danger-hover: #9c1925;

  /* ---- Shape & motion ---- */
  --radius:    10px;
  --radius-sm: 6px;
  --radius-lg: 16px;
  --shadow:    0 1px 3px rgba(16,24,40,.08), 0 4px 12px rgba(16,24,40,.06);
  --shadow-lg: 0 12px 32px rgba(16,24,40,.18);
  --focus:     0 0 0 3px var(--accent-soft);

  /* ---- Spacing scale ---- */
  --sp-1: 4px;  --sp-2: 8px;  --sp-3: 12px;
  --sp-4: 16px; --sp-5: 24px; --sp-6: 32px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica,
          Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body {
  margin: 0;
  padding: 0;
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 15px;
  line-height: 1.5;
  -webkit-text-size-adjust: 100%;
}

h1, h2, h3 { margin: 0 0 var(--sp-3); line-height: 1.25; }
a { color: var(--accent); }

/* ---------------- Buttons ---------------- */
.btn-primary, .btn-secondary, .btn-danger, .btn-ghost {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: var(--sp-2);
  min-height: 40px;
  padding: 8px 16px;
  border-radius: var(--radius-sm);
  border: 1px solid transparent;
  font: inherit;
  font-weight: 600;
  cursor: pointer;
  transition: background .15s, border-color .15s, opacity .15s;
  text-decoration: none;
}
.btn-primary  { background: var(--accent); color: var(--text-invert); }
.btn-primary:hover  { background: var(--accent-hover); }
.btn-secondary { background: var(--surface); color: var(--text); border-color: var(--border); }
.btn-secondary:hover { background: var(--surface-2); }
.btn-danger  { background: var(--danger); color: var(--text-invert); }
.btn-danger:hover  { background: var(--danger-hover); }
.btn-ghost   { background: transparent; color: var(--text-muted); }
.btn-ghost:hover { background: var(--surface-2); color: var(--text); }
.btn-primary:disabled, .btn-secondary:disabled, .btn-danger:disabled {
  opacity: .55; cursor: not-allowed;
}
button:focus-visible, a:focus-visible, input:focus-visible,
select:focus-visible, textarea:focus-visible {
  outline: none;
  box-shadow: var(--focus);
}

/* ---------------- Pills ---------------- */
.pill {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 3px 10px;
  border-radius: 999px;
  font-size: 12px;
  font-weight: 600;
  background: var(--surface-2);
  color: var(--text-muted);
}
.pill-accent  { background: var(--accent-soft); color: var(--accent-hover); }
.pill-success { background: #e3f5ec; color: var(--success); }
.pill-warning { background: #fbf0dd; color: var(--warning); }
.pill-danger  { background: #fbe6e8; color: var(--danger); }

/* ---------------- Cards ---------------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: var(--sp-5);
  box-shadow: var(--shadow);
}

/* ---------------- Inputs ---------------- */
.input, select.input, textarea.input {
  width: 100%;
  box-sizing: border-box;
  padding: 10px 12px;
  border: 1px solid var(--border);
  border-radius: var(--radius-sm);
  background: var(--surface);
  font: inherit;
  color: var(--text);
}
.field-label {
  display: block;
  font-size: 13px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 6px;
}

/* ---------------- Tables ---------------- */
.table-wrapper {
  width: 100%;
  overflow-x: auto;
  -webkit-overflow-scrolling: touch;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}
.table-wrapper table { width: 100%; border-collapse: collapse; min-width: 480px; }
.table-wrapper th, .table-wrapper td {
  padding: 10px 14px;
  text-align: left;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}
.table-wrapper th {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: .04em;
  color: var(--text-muted);
  background: var(--surface-2);
}
.table-wrapper tr:last-child td { border-bottom: none; }

/* ---------------- Toolbar (filter rows) ---------------- */
.toolbar {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  align-items: center;
}
.toolbar .search { flex: 1; min-width: 200px; }

/* ---------------- Responsive grid helper ---------------- */
.grid {
  display: grid;
  gap: var(--sp-4);
  grid-template-columns: repeat(auto-fit, minmax(min(100%, 240px), 1fr));
}
.grid > * { min-width: 0; }

/* ---------------- Toast ---------------- */
#toast-root {
  position: fixed;
  bottom: calc(env(safe-area-inset-bottom, 0px) + 16px);
  left: 50%;
  transform: translateX(-50%);
  display: flex;
  flex-direction: column;
  gap: var(--sp-2);
  z-index: 9999;
  width: min(92vw, 380px);
}
.toast {
  background: var(--text);
  color: var(--text-invert);
  padding: 12px 16px;
  border-radius: var(--radius-sm);
  box-shadow: var(--shadow-lg);
  font-size: 14px;
  animation: toast-in .18s ease-out;
}
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }

/* ---------------- Modal / Confirm ---------------- */
#modal-root {
  position: fixed;
  inset: 0;
  z-index: 9000;
  display: none;
  align-items: center;
  justify-content: center;
  padding: var(--sp-4);
  background: var(--overlay);
}
#modal-root.open { display: flex; }
.modal {
  background: var(--surface);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  width: 100%;
  max-width: 460px;
  padding: var(--sp-5);
  animation: toast-in .18s ease-out;
}
.modal h3 { margin-bottom: var(--sp-2); }
.modal p  { color: var(--text-muted); margin: 0 0 var(--sp-5); }
.modal-actions {
  display: flex;
  flex-wrap: wrap;
  gap: var(--sp-2);
  justify-content: flex-end;
}

.muted { color: var(--text-muted); }
.center { text-align: center; }
