@import "tailwindcss";

:root {
  --bg: #ffffff;
  --surface: #f9f9fb;
  --surface-elevated: #ffffff;
  --surface-hover: #f4f4f6;
  --border: #e4e4e7;
  --border-subtle: #f0f0f2;
  --border-muted: #d4d4d8;
  --text: #09090b;
  --text-muted: #52525b;
  --text-dim: #a1a1aa;
  --accent: #d97706;
  --accent-light: #f59e0b;
  --accent-hover: #b45309;
  --accent-glow: rgba(217, 119, 6, 0.1);
  --accent-glow-strong: rgba(217, 119, 6, 0.18);
  --success: #059669;
  --success-muted: rgba(5, 150, 105, 0.08);
  --error: #dc2626;
  --error-muted: rgba(220, 38, 38, 0.08);
  --warning: #d97706;
  --warning-muted: rgba(217, 119, 6, 0.08);
  --info: #2563eb;
  --info-muted: rgba(37, 99, 235, 0.08);
}

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

  html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
  }

  body {
    background-color: var(--bg);
    color: var(--text);
    font-family: 'DM Sans', system-ui, sans-serif;
    min-height: 100vh;
  }

  /* Custom scrollbar */
  ::-webkit-scrollbar {
    width: 5px;
    height: 5px;
  }
  ::-webkit-scrollbar-track {
    background: var(--bg);
  }
  ::-webkit-scrollbar-thumb {
    background: var(--border);
    border-radius: 3px;
  }
  ::-webkit-scrollbar-thumb:hover {
    background: var(--border-muted);
  }

  /* Selection */
  ::selection {
    background: rgba(217, 119, 6, 0.2);
    color: var(--text);
  }

  /* Details/summary reset */
  details summary {
    list-style: none;
  }
  details summary::-webkit-details-marker {
    display: none;
  }

  /* Native select styling */
  select.input option {
    background: var(--surface-elevated);
    color: var(--text);
  }
}

@layer components {

  /* ───────────── BUTTONS ───────────── */

  .btn-primary {
    @apply inline-flex items-center gap-2 px-4 py-2 text-sm font-semibold rounded-lg transition-all duration-200 cursor-pointer border-0 no-underline;
    background: var(--accent);
    color: #ffffff;
  }
  .btn-primary:hover {
    background: var(--accent-hover);
    box-shadow: 0 0 0 1px var(--accent-hover), 0 4px 24px var(--accent-glow-strong);
    transform: translateY(-1px);
  }
  .btn-primary:active {
    transform: translateY(0);
  }

  .btn-secondary {
    @apply inline-flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-lg transition-all duration-200 cursor-pointer no-underline;
    background: var(--surface-elevated);
    color: var(--text-muted);
    border: 1px solid var(--border);
  }
  .btn-secondary:hover {
    color: var(--text);
    border-color: var(--border-muted);
    background: var(--surface-hover);
  }

  .btn-danger {
    @apply inline-flex items-center gap-2 px-4 py-2 text-sm font-medium rounded-lg transition-all duration-200 cursor-pointer no-underline;
    background: var(--error-muted);
    color: var(--error);
    border: 1px solid rgba(220, 38, 38, 0.2);
  }
  .btn-danger:hover {
    background: rgba(220, 38, 38, 0.14);
    border-color: rgba(220, 38, 38, 0.4);
  }

  .btn-ghost {
    @apply inline-flex items-center gap-2 px-3 py-1.5 text-xs font-medium rounded-md transition-all duration-200 cursor-pointer no-underline;
    background: transparent;
    color: var(--text-dim);
    border: 1px solid transparent;
  }
  .btn-ghost:hover {
    color: var(--text-muted);
    background: var(--surface-hover);
    border-color: var(--border-subtle);
  }

  /* ───────────── FORMS ───────────── */

  .input {
    @apply block w-full rounded-lg px-3 py-2 text-sm transition-all duration-200;
    background: var(--surface);
    color: var(--text);
    border: 1px solid var(--border);
    outline: none;
    font-family: inherit;
  }
  .input::placeholder {
    color: var(--text-dim);
  }
  .input:focus {
    border-color: var(--accent);
    box-shadow: 0 0 0 3px var(--accent-glow);
  }

  textarea.input {
    resize: vertical;
    min-height: 5rem;
  }

  .label {
    @apply block text-xs font-semibold uppercase tracking-widest mb-2;
    color: var(--text-dim);
    letter-spacing: 0.07em;
  }

  /* ───────────── BADGES ───────────── */

  .badge-active,
  .badge-completed,
  .badge-published,
  .badge-locked {
    @apply inline-flex items-center px-2 py-0.5 rounded text-xs font-semibold;
    background: rgba(5, 150, 105, 0.08);
    color: #059669;
    border: 1px solid rgba(5, 150, 105, 0.2);
  }
  .badge-released {
    @apply inline-flex items-center px-2 py-0.5 rounded text-xs font-semibold;
    background: rgba(113, 113, 122, 0.08);
    color: #71717a;
    border: 1px solid rgba(113, 113, 122, 0.2);
  }
  .badge-paused,
  .badge-skipped,
  .badge-pending {
    @apply inline-flex items-center px-2 py-0.5 rounded text-xs font-semibold;
    background: rgba(217, 119, 6, 0.08);
    color: #d97706;
    border: 1px solid rgba(217, 119, 6, 0.2);
  }
  .badge-failed {
    @apply inline-flex items-center px-2 py-0.5 rounded text-xs font-semibold;
    background: rgba(220, 38, 38, 0.08);
    color: #dc2626;
    border: 1px solid rgba(220, 38, 38, 0.2);
  }
  .badge-running {
    @apply inline-flex items-center px-2 py-0.5 rounded text-xs font-semibold;
    background: rgba(37, 99, 235, 0.08);
    color: #2563eb;
    border: 1px solid rgba(37, 99, 235, 0.2);
  }
  .badge-partial {
    @apply inline-flex items-center px-2 py-0.5 rounded text-xs font-semibold;
    background: rgba(234, 88, 12, 0.08);
    color: #ea580c;
    border: 1px solid rgba(234, 88, 12, 0.2);
  }
  .badge-member {
    @apply inline-flex items-center px-2 py-0.5 rounded text-xs font-semibold;
    background: rgba(113, 113, 122, 0.08);
    color: #71717a;
    border: 1px solid rgba(113, 113, 122, 0.2);
  }
  .badge-owner {
    @apply inline-flex items-center px-2 py-0.5 rounded text-xs font-semibold;
    background: var(--accent-glow);
    color: var(--accent);
    border: 1px solid rgba(217, 119, 6, 0.25);
  }

  /* ───────────── STEP BADGES ───────────── */

  .step-badge-pending {
    @apply inline-flex items-center px-2 py-0.5 rounded text-xs font-medium;
    background: rgba(113, 113, 122, 0.08);
    color: #71717a;
    border: 1px solid rgba(113, 113, 122, 0.15);
  }
  .step-badge-running {
    @apply inline-flex items-center px-2 py-0.5 rounded text-xs font-medium;
    background: rgba(37, 99, 235, 0.08);
    color: #2563eb;
    border: 1px solid rgba(37, 99, 235, 0.2);
  }
  .step-badge-completed {
    @apply inline-flex items-center px-2 py-0.5 rounded text-xs font-medium;
    background: rgba(5, 150, 105, 0.08);
    color: #059669;
    border: 1px solid rgba(5, 150, 105, 0.2);
  }
  .step-badge-failed {
    @apply inline-flex items-center px-2 py-0.5 rounded text-xs font-medium;
    background: rgba(220, 38, 38, 0.08);
    color: #dc2626;
    border: 1px solid rgba(220, 38, 38, 0.2);
  }
  .step-badge-skipped {
    @apply inline-flex items-center px-2 py-0.5 rounded text-xs font-medium;
    background: rgba(113, 113, 122, 0.06);
    color: #a1a1aa;
    border: 1px solid rgba(113, 113, 122, 0.1);
  }

  /* ───────────── CARD ───────────── */

  .card {
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    border-radius: 0.75rem;
  }

  /* ───────────── PAGE HEADER ───────────── */

  .page-header {
    @apply flex items-center justify-between mb-8;
  }

  .page-title {
    @apply text-2xl font-semibold tracking-tight;
    color: var(--text);
    font-family: 'Fraunces', Georgia, serif;
  }

  .page-subtitle {
    @apply text-sm mt-1;
    color: var(--text-dim);
  }

  /* ───────────── SECTION CARD ───────────── */

  .section-card {
    @apply rounded-xl p-6;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
  }

  .section-title {
    @apply text-sm font-semibold uppercase tracking-widest mb-4;
    color: var(--text-dim);
    letter-spacing: 0.07em;
  }

  /* ───────────── DATA TABLE ───────────── */

  .data-table {
    @apply w-full text-sm;
  }
  .data-table thead th {
    @apply px-6 py-3 text-left text-xs font-semibold uppercase tracking-widest;
    color: var(--text-dim);
    border-bottom: 1px solid var(--border);
    letter-spacing: 0.07em;
  }
  .data-table tbody tr {
    border-bottom: 1px solid var(--border-subtle);
    transition: background-color 0.12s;
  }
  .data-table tbody tr:hover {
    background: rgba(0, 0, 0, 0.02);
  }
  .data-table tbody tr:last-child {
    border-bottom: none;
  }
  .data-table tbody td {
    @apply px-6 py-4;
    color: var(--text-muted);
  }

  .money-page-monitor-table thead th {
    padding-left: 0.85rem;
    padding-right: 0.85rem;
  }

  .money-page-monitor-table tbody td {
    padding: 0.95rem 0.85rem;
    vertical-align: top;
  }

  .money-page-monitor-table thead th:first-child,
  .money-page-monitor-table tbody td:first-child {
    position: sticky;
    left: 0;
    background: var(--surface-elevated);
    box-shadow: 10px 0 14px -14px rgba(15, 23, 42, 0.22);
  }

  .money-page-monitor-table thead th:first-child {
    z-index: 3;
  }

  .money-page-monitor-table tbody td:first-child {
    z-index: 2;
  }

  .money-page-monitor-table thead th {
    position: sticky;
    top: 0;
    background: var(--surface-elevated);
    z-index: 1;
  }

  /* ───────────── EMPTY STATE ───────────── */

  .empty-state {
    @apply flex flex-col items-center justify-center py-16 text-center;
  }
  .empty-state-icon {
    @apply mb-4 text-4xl opacity-20;
  }
  .empty-state-title {
    @apply text-base font-medium mb-2;
    color: var(--text-muted);
  }
  .empty-state-text {
    @apply text-sm mb-6;
    color: var(--text-dim);
  }

  /* ───────────── FLASH ───────────── */

  .flash-notice {
    @apply flex items-center gap-3 px-4 py-3 rounded-lg text-sm mb-4;
    background: rgba(5, 150, 105, 0.07);
    color: #059669;
    border: 1px solid rgba(5, 150, 105, 0.18);
  }
  .flash-alert {
    @apply flex items-center gap-3 px-4 py-3 rounded-lg text-sm mb-4;
    background: rgba(220, 38, 38, 0.07);
    color: #dc2626;
    border: 1px solid rgba(220, 38, 38, 0.18);
  }

  /* ───────────── LINK ───────────── */

  .link-accent {
    @apply text-sm transition-colors duration-150;
    color: var(--accent);
  }
  .link-accent:hover {
    color: var(--accent-light);
  }

  .link-muted {
    @apply text-sm transition-colors duration-150 no-underline;
    color: var(--text-dim);
  }
  .link-muted:hover {
    color: var(--text-muted);
  }

  /* ───────────── MONO DATA ───────────── */

  .mono {
    font-family: 'DM Mono', 'Fira Code', monospace;
    font-size: 0.8125rem;
  }

  /* ───────────── AUTH LAYOUT ───────────── */

  .auth-container {
    @apply min-h-screen flex flex-col items-center justify-center px-4 py-12;
    background:
      radial-gradient(ellipse 80% 60% at 50% -10%, rgba(217, 119, 6, 0.05) 0%, transparent 70%),
      var(--bg);
  }

  .auth-card {
    @apply w-full max-w-sm rounded-2xl p-8;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
    box-shadow:
      0 0 0 1px var(--border-subtle),
      0 8px 40px rgba(0, 0, 0, 0.06),
      0 0 80px rgba(217, 119, 6, 0.03);
  }

  .auth-logo {
    @apply text-2xl font-bold tracking-tight mb-8 text-center;
    font-family: 'Fraunces', Georgia, serif;
    color: var(--accent);
  }

  .auth-title {
    @apply text-lg font-semibold mb-1;
    color: var(--text);
    font-family: 'Fraunces', Georgia, serif;
  }

  .auth-subtitle {
    @apply text-sm mb-6;
    color: var(--text-dim);
  }

  .auth-divider {
    @apply flex items-center gap-3 my-5;
  }
  .auth-divider::before,
  .auth-divider::after {
    content: '';
    @apply flex-1 h-px;
    background: var(--border);
  }
  .auth-divider span {
    @apply text-xs;
    color: var(--text-dim);
  }

  .auth-footer {
    @apply mt-6 text-center text-sm;
    color: var(--text-dim);
  }
  .auth-footer a {
    color: var(--accent);
    text-decoration: none;
  }
  .auth-footer a:hover {
    color: var(--accent-light);
  }

  /* ───────────── NAV ───────────── */

  .nav-link {
    @apply text-sm font-medium px-3 py-1.5 rounded-md transition-all duration-150 no-underline;
    color: var(--text-dim);
  }
  .nav-link:hover {
    color: var(--text-muted);
    background: var(--surface-hover);
  }
  .nav-link.active {
    color: var(--text);
    background: var(--surface-hover);
  }

  /* ───────────── WORKFLOW CARD ───────────── */

  .workflow-card {
    @apply rounded-xl p-5 transition-all duration-200;
    background: var(--surface-elevated);
    border: 1px solid var(--border);
  }
  .workflow-card:hover {
    border-color: var(--border-muted);
    background: var(--surface-hover);
  }

  /* ───────────── STEP TIMELINE ───────────── */

  .step-row {
    border-bottom: 1px solid var(--border-subtle);
    transition: background 0.12s;
  }
  .step-row:last-child {
    border-bottom: none;
  }
  .step-row summary:hover {
    background: rgba(0, 0, 0, 0.02);
  }

  /* ───────────── CHECKBOX ───────────── */

  .checkbox-label {
    @apply flex items-center gap-2.5 cursor-pointer text-sm py-1 px-2 rounded-md transition-colors duration-100;
    color: var(--text-muted);
  }
  .checkbox-label:hover {
    background: var(--surface-hover);
    color: var(--text);
  }
  .checkbox-label input[type="checkbox"] {
    accent-color: var(--accent);
    width: 15px;
    height: 15px;
    cursor: pointer;
  }

  .cluster-row-active td {
    background: rgba(217, 119, 6, 0.07);
    border-top-color: rgba(217, 119, 6, 0.14);
    border-bottom-color: rgba(217, 119, 6, 0.14);
  }

  .cluster-row-active td:first-child {
    box-shadow: inset 3px 0 0 0 var(--accent);
  }

  .cluster-editor-inline-row td {
    padding: 0;
    border-top: 0;
    background: transparent;
  }

  .cluster-editor-inline-cell {
    padding: 0;
  }

  .cluster-editor-inline-shell {
    margin-top: 0.65rem;
    border-radius: 1.5rem;
    background: var(--surface);
    border: 1px solid rgba(217, 119, 6, 0.14);
    box-shadow: 0 10px 24px rgba(15, 23, 42, 0.04);
    padding: 1.25rem;
  }
}
