/*
 * Corp UI Design Kit
 * Drop this file into your iframe app and your UI will match the host console.
 *
 *   <link rel="stylesheet" href="/design-kit/corp-ui.css">
 *
 * Light/dark is controlled by a `data-theme="dark"` attribute on <html>.
 * The corp-sdk.js helper sets this automatically based on host messages.
 */

:root {
  --brand-50:  #fff7ed;
  --brand-100: #ffedd5;
  --brand-200: #fed7aa;
  --brand-300: #fdba74;
  --brand-400: #fb923c;
  --brand-500: #f97316;
  --brand-600: #ea580c;
  --brand-700: #c2410c;

  --bg:        #ffffff;
  --bg-elev:   #ffffff;
  --bg-muted:  #fafafa;
  --fg:        #18181b;
  --fg-muted:  #71717a;
  --fg-faint:  #a1a1aa;
  --border:    #e4e4e7;
  --border-strong: #d4d4d8;
  --shadow:    0 1px 2px rgba(0,0,0,0.04), 0 4px 12px -6px rgba(0,0,0,0.08);
  --shadow-glow: 0 10px 30px -10px rgba(249, 115, 22, 0.45);

  --radius-sm: 8px;
  --radius:    12px;
  --radius-lg: 16px;
}

:root[data-theme="dark"] {
  --bg:        #09090b;
  --bg-elev:   #18181b;
  --bg-muted:  #18181b;
  --fg:        #fafafa;
  --fg-muted:  #a1a1aa;
  --fg-faint:  #52525b;
  --border:    #27272a;
  --border-strong: #3f3f46;
  --shadow:    0 1px 2px rgba(0,0,0,0.4), 0 4px 12px -6px rgba(0,0,0,0.5);
}

*, *::before, *::after { box-sizing: border-box; }

html, body {
  margin: 0;
  background: var(--bg);
  color: var(--fg);
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, "Segoe UI", Roboto, sans-serif;
  font-size: 14px;
  line-height: 1.5;
  -webkit-font-smoothing: antialiased;
}

a { color: var(--brand-600); text-decoration: none; }
a:hover { color: var(--brand-500); }

h1, h2, h3, h4 { letter-spacing: -0.01em; margin: 0; }
h1 { font-size: 24px; font-weight: 600; }
h2 { font-size: 18px; font-weight: 600; }
h3 { font-size: 15px; font-weight: 600; }
p  { margin: 0 0 0.5em; color: var(--fg); }

.cui-container { max-width: 72rem; margin: 0 auto; padding: 16px; }
@media (min-width: 640px) { .cui-container { padding: 24px; } }

.cui-card {
  background: var(--bg-elev);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 16px;
  box-shadow: var(--shadow);
}
@media (min-width: 640px) { .cui-card { padding: 24px; } }

.cui-btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 8px;
  padding: 8px 16px; font-size: 14px; font-weight: 500;
  border-radius: var(--radius); border: 1px solid transparent;
  cursor: pointer; transition: background 0.15s, color 0.15s, border-color 0.15s, box-shadow 0.15s;
  background: transparent; color: var(--fg);
  font-family: inherit;
}
.cui-btn:focus-visible {
  outline: none;
  box-shadow: 0 0 0 2px var(--bg), 0 0 0 4px var(--brand-400);
}
.cui-btn:disabled { opacity: 0.55; cursor: not-allowed; }

.cui-btn-primary {
  background: var(--brand-500); color: white; box-shadow: var(--shadow-glow);
}
.cui-btn-primary:hover:not(:disabled) { background: var(--brand-600); }

.cui-btn-secondary {
  background: var(--bg-muted); color: var(--fg); border-color: var(--border);
}
.cui-btn-secondary:hover:not(:disabled) { background: var(--border); }

.cui-btn-ghost { color: var(--fg-muted); }
.cui-btn-ghost:hover:not(:disabled) { background: var(--bg-muted); color: var(--fg); }

.cui-btn-danger { background: #ef4444; color: white; }
.cui-btn-danger:hover:not(:disabled) { background: #dc2626; }

.cui-input, .cui-select, .cui-textarea {
  width: 100%; padding: 8px 12px; font-size: 14px; line-height: 1.4;
  background: var(--bg-elev); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--radius);
  transition: border-color 0.15s, box-shadow 0.15s;
  font-family: inherit;
}
.cui-textarea { min-height: 80px; resize: vertical; }
.cui-input:focus, .cui-select:focus, .cui-textarea:focus {
  outline: none; border-color: var(--brand-400);
  box-shadow: 0 0 0 3px rgba(249, 115, 22, 0.15);
}

.cui-label { display: block; font-size: 13px; font-weight: 500; color: var(--fg-muted); margin-bottom: 6px; }

.cui-badge {
  display: inline-flex; align-items: center; padding: 2px 10px;
  font-size: 11px; font-weight: 500; line-height: 1.5;
  border-radius: 999px; background: var(--bg-muted); color: var(--fg-muted);
  border: 1px solid var(--border);
}
.cui-badge-brand { background: var(--brand-50); color: var(--brand-700); border-color: var(--brand-200); }
:root[data-theme="dark"] .cui-badge-brand {
  background: rgba(249, 115, 22, 0.12); color: var(--brand-300); border-color: rgba(249, 115, 22, 0.25);
}

.cui-table {
  width: 100%; border-collapse: collapse; font-size: 14px;
  background: var(--bg-elev); border: 1px solid var(--border);
  border-radius: var(--radius-lg); overflow: hidden;
}
.cui-table thead { background: var(--bg-muted); }
.cui-table th, .cui-table td {
  padding: 12px 16px; text-align: left; border-top: 1px solid var(--border);
}
.cui-table thead th { color: var(--fg-muted); font-weight: 500; font-size: 12px;
  text-transform: uppercase; letter-spacing: 0.04em; border-top: 0; }

/* Wrap a wide table in this so it scrolls horizontally instead of pushing
   the whole page off-screen on mobile. Pair with min-width on .cui-table. */
.cui-table-scroll { overflow-x: auto; -webkit-overflow-scrolling: touch; }

.cui-divider { height: 1px; background: var(--border); margin: 16px 0; border: 0; }

.cui-toolbar {
  display: flex; align-items: center; justify-content: space-between;
  padding: 16px 24px; border-bottom: 1px solid var(--border); background: var(--bg-elev);
}

/* ============================================================
 * Widgets used by corp-ui.js (toasts + confirm modal).
 * ============================================================ */

.cui-toasts {
  position: fixed; top: 16px; right: 16px; z-index: 9999;
  display: flex; flex-direction: column; gap: 8px;
  width: min(360px, calc(100vw - 32px));
  pointer-events: none;
}
.cui-toast {
  pointer-events: auto;
  display: flex; align-items: flex-start; gap: 10px;
  padding: 10px 12px; border-radius: var(--radius);
  background: var(--bg-elev); color: var(--fg);
  border: 1px solid var(--border); box-shadow: var(--shadow);
  font-size: 13px; line-height: 1.4;
  animation: cui-toast-in 180ms ease-out;
}
.cui-toast.cui-toast-leaving {
  animation: cui-toast-out 160ms ease-in forwards;
}
.cui-toast-icon {
  flex-shrink: 0; width: 18px; height: 18px;
  display: inline-flex; align-items: center; justify-content: center;
  border-radius: 999px; color: white; font-weight: 600; font-size: 11px;
}
.cui-toast-success .cui-toast-icon { background: #16a34a; }
.cui-toast-error   .cui-toast-icon { background: #dc2626; }
.cui-toast-info    .cui-toast-icon { background: var(--brand-500); }
.cui-toast-loading .cui-toast-icon {
  background: var(--bg-muted); color: var(--fg-muted);
  border: 2px solid var(--border-strong); border-top-color: var(--brand-500);
  animation: cui-spin 700ms linear infinite;
}
.cui-toast-body { flex: 1; min-width: 0; word-break: break-word; }
.cui-toast-close {
  flex-shrink: 0; appearance: none; border: 0; background: transparent;
  color: var(--fg-faint); cursor: pointer; padding: 0 2px; font-size: 14px;
  line-height: 1; align-self: flex-start;
}
.cui-toast-close:hover { color: var(--fg); }
@keyframes cui-toast-in {
  from { transform: translateX(20px); opacity: 0; }
  to   { transform: translateX(0);    opacity: 1; }
}
@keyframes cui-toast-out {
  from { transform: translateX(0);    opacity: 1; }
  to   { transform: translateX(20px); opacity: 0; }
}
@keyframes cui-spin { to { transform: rotate(360deg); } }

.cui-modal-backdrop {
  position: fixed; inset: 0; z-index: 9998;
  background: rgba(0, 0, 0, 0.4);
  backdrop-filter: blur(8px); -webkit-backdrop-filter: blur(8px);
  display: flex; align-items: center; justify-content: center;
  padding: 16px; overflow-y: auto;
  animation: cui-fade-in 140ms ease-out;
}
.cui-modal-card {
  background: var(--bg-elev); color: var(--fg);
  border: 1px solid var(--border); border-radius: var(--radius-lg);
  box-shadow: var(--shadow);
  width: 100%; max-width: 420px;
  padding: 20px;
  animation: cui-modal-in 160ms ease-out;
}
.cui-modal-title { font-weight: 600; font-size: 16px; margin: 0 0 8px; }
.cui-modal-message { color: var(--fg-muted); font-size: 13px; margin: 0 0 16px; }
.cui-modal-actions {
  display: flex; flex-direction: column-reverse; gap: 8px;
}
@media (min-width: 480px) {
  .cui-modal-actions { flex-direction: row; justify-content: flex-end; }
  .cui-modal-actions > .cui-btn { width: auto; }
}
.cui-modal-actions > .cui-btn { width: 100%; }
@keyframes cui-fade-in   { from { opacity: 0; } to { opacity: 1; } }
@keyframes cui-modal-in  {
  from { opacity: 0; transform: translateY(8px); }
  to   { opacity: 1; transform: translateY(0); }
}
