/* ============================================================
   Countr — Application Stylesheet
   Dark mode, clean & professional
   ============================================================ */

/* ── Variables ─────────────────────────────────────────────── */
:root {
  --radius-sm:  4px;
  --radius-md:  8px;
  --radius-lg:  12px;

  --shadow-sm:  0 1px 3px rgba(0,0,0,.4);
  --shadow-md:  0 4px 16px rgba(0,0,0,.5);
  --shadow-lg:  0 8px 32px rgba(0,0,0,.6);

  --font:       -apple-system, BlinkMacSystemFont, 'Segoe UI', system-ui, sans-serif;
  --font-mono:  'SFMono-Regular', Consolas, 'Liberation Mono', Menlo, monospace;

  --sidebar-w: 220px;
  --topbar-h:   56px;
}

[data-theme="dark"] {
  --bg-base:        #0d1117;
  --bg-surface:     #161b22;
  --bg-elevated:    #21262d;
  --bg-hover:       #30363d;

  --border:         #30363d;
  --border-subtle:  #21262d;

  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #6e7681;

  --accent:         #2f81f7;
  --accent-hover:   #58a6ff;
  --accent-subtle:  rgba(47, 129, 247, 0.12);

  --success:        #3fb950;
  --success-subtle: rgba(63, 185, 80, 0.12);

  --danger:         #f85149;
  --danger-subtle:  rgba(248, 81, 73, 0.12);

  --warning:        #d29922;
  --warning-subtle: rgba(210, 153, 34, 0.12);
}

[data-theme="light"] {
  --bg-base:        #f6f8fa;
  --bg-surface:     #ffffff;
  --bg-elevated:    #f0f2f4;
  --bg-hover:       #e8eaed;

  --border:         #d0d7de;
  --border-subtle:  #e8eaed;

  --text-primary:   #1f2328;
  --text-secondary: #636c76;
  --text-muted:     #9198a1;

  --accent:         #2f81f7;
  --accent-hover:   #0969da;
  --accent-subtle:  rgba(47, 129, 247, 0.12);

  --success:        #3fb950;
  --success-subtle: rgba(63, 185, 80, 0.12);

  --danger:         #f85149;
  --danger-subtle:  rgba(248, 81, 73, 0.12);

  --warning:        #d29922;
  --warning-subtle: rgba(210, 153, 34, 0.12);
}

/* Auto theme: CSS fallback when JS is unavailable */
[data-theme="auto"] {
  --bg-base:        #0d1117;
  --bg-surface:     #161b22;
  --bg-elevated:    #21262d;
  --bg-hover:       #30363d;
  --border:         #30363d;
  --border-subtle:  #21262d;
  --text-primary:   #e6edf3;
  --text-secondary: #8b949e;
  --text-muted:     #6e7681;
  --accent:         #2f81f7;
  --accent-hover:   #58a6ff;
  --accent-subtle:  rgba(47, 129, 247, 0.12);
  --success:        #3fb950;
  --success-subtle: rgba(63, 185, 80, 0.12);
  --danger:         #f85149;
  --danger-subtle:  rgba(248, 81, 73, 0.12);
  --warning:        #d29922;
  --warning-subtle: rgba(210, 153, 34, 0.12);
}

@media (prefers-color-scheme: light) {
  [data-theme="auto"] {
    --bg-base:        #f6f8fa;
    --bg-surface:     #ffffff;
    --bg-elevated:    #f0f2f4;
    --bg-hover:       #e8eaed;
    --border:         #d0d7de;
    --border-subtle:  #e8eaed;
    --text-primary:   #1f2328;
    --text-secondary: #636c76;
    --text-muted:     #9198a1;
    --accent:         #2f81f7;
    --accent-hover:   #0969da;
    --accent-subtle:  rgba(47, 129, 247, 0.12);
    --success:        #3fb950;
    --success-subtle: rgba(63, 185, 80, 0.12);
    --danger:         #f85149;
    --danger-subtle:  rgba(248, 81, 73, 0.12);
    --warning:        #d29922;
    --warning-subtle: rgba(210, 153, 34, 0.12);
  }
}

@media (prefers-color-scheme: dark) {
  [data-theme="auto"] {
    --bg-base:        #0d1117;
    --bg-surface:     #161b22;
    --bg-elevated:    #21262d;
    --bg-hover:       #30363d;
    --border:         #30363d;
    --border-subtle:  #21262d;
    --text-primary:   #e6edf3;
    --text-secondary: #8b949e;
    --text-muted:     #6e7681;
    --accent:         #2f81f7;
    --accent-hover:   #58a6ff;
    --accent-subtle:  rgba(47, 129, 247, 0.12);
    --success:        #3fb950;
    --success-subtle: rgba(63, 185, 80, 0.12);
    --danger:         #f85149;
    --danger-subtle:  rgba(248, 81, 73, 0.12);
    --warning:        #d29922;
    --warning-subtle: rgba(210, 153, 34, 0.12);
  }
}

/* ── Reset ──────────────────────────────────────────────────── */
*, *::before, *::after {
  box-sizing: border-box;
  margin: 0;
  padding: 0;
}

html {
  font-size: 14px;
  -webkit-text-size-adjust: 100%;
}

body {
  font-family: var(--font);
  background: var(--bg-base);
  color: var(--text-primary);
  line-height: 1.6;
  min-height: 100vh;
  -webkit-font-smoothing: antialiased;
}

a {
  color: var(--accent);
  text-decoration: none;
}

a:hover {
  color: var(--accent-hover);
  text-decoration: underline;
}

/* ── Typography ─────────────────────────────────────────────── */
h1, h2, h3, h4, h5, h6 {
  font-weight: 600;
  line-height: 1.25;
  color: var(--text-primary);
}

h1 { font-size: 1.714rem; }
h2 { font-size: 1.429rem; }
h3 { font-size: 1.214rem; }
h4 { font-size: 1rem; }

p { color: var(--text-secondary); }

code, pre {
  font-family: var(--font-mono);
  font-size: 0.9em;
}

/* ── Utilities ──────────────────────────────────────────────── */
.text-muted     { color: var(--text-muted); }
.text-secondary { color: var(--text-secondary); }
.text-success   { color: var(--success); }
.text-danger    { color: var(--danger); }
.text-warning   { color: var(--warning); }
.text-accent    { color: var(--accent); }

.mt-1 { margin-top: 0.25rem; }
.mt-2 { margin-top: 0.5rem; }
.mt-4 { margin-top: 1rem; }
.mt-6 { margin-top: 1.5rem; }
.mb-4 { margin-bottom: 1rem; }
.mb-6 { margin-bottom: 1.5rem; }

.d-flex         { display: flex; }
.align-center   { align-items: center; }
.justify-between{ justify-content: space-between; }
.gap-2          { gap: 0.5rem; }
.gap-3          { gap: 0.75rem; }
.gap-4          { gap: 1rem; }

.w-full { width: 100%; }
.sr-only {
  position: absolute;
  width: 1px;
  height: 1px;
  padding: 0;
  margin: -1px;
  overflow: hidden;
  clip: rect(0,0,0,0);
  white-space: nowrap;
  border-width: 0;
}

/* ── Buttons ────────────────────────────────────────────────── */
.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 0.375rem;
  padding: 0.5rem 1rem;
  font-size: 0.875rem;
  font-weight: 500;
  font-family: var(--font);
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  cursor: pointer;
  text-decoration: none;
  transition: background 0.15s, border-color 0.15s, color 0.15s, box-shadow 0.15s;
  white-space: nowrap;
  line-height: 1;
}

.btn:disabled {
  opacity: 0.5;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent, #2f81f7);
  color: #fff;
  border-color: var(--accent, #2f81f7);
}

.btn-primary:hover:not(:disabled) {
  background: var(--accent-hover);
  border-color: var(--accent-hover);
  color: #fff;
  text-decoration: none;
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.btn-secondary {
  background: var(--bg-elevated);
  color: var(--text-primary);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--bg-hover);
  border-color: var(--text-muted);
  color: var(--text-primary);
  text-decoration: none;
}

.btn-danger {
  background: transparent;
  color: var(--danger);
  border-color: var(--danger);
}

.btn-danger:hover:not(:disabled) {
  background: var(--danger-subtle);
  text-decoration: none;
}

.btn-ghost {
  background: transparent;
  color: var(--text-secondary);
  border-color: transparent;
}

.btn-ghost:hover:not(:disabled) {
  background: var(--bg-elevated);
  color: var(--text-primary);
  text-decoration: none;
}

.btn-sm {
  padding: 0.3rem 0.65rem;
  font-size: 0.8125rem;
}

.btn-lg {
  padding: 0.75rem 1.5rem;
  font-size: 1rem;
}

.btn-block {
  display: flex;
  width: 100%;
}

/* ── Forms ──────────────────────────────────────────────────── */
.form-group {
  display: flex;
  flex-direction: column;
  gap: 0.375rem;
}

.form-label {
  font-size: 0.8125rem;
  font-weight: 500;
  color: var(--text-secondary);
  letter-spacing: 0.01em;
}

.form-input,
.form-select,
.form-textarea {
  width: 100%;
  padding: 0.5rem 0.75rem;
  background: var(--bg-base);
  border: 1px solid var(--border);
  border-radius: var(--radius-md);
  color: var(--text-primary);
  font-family: var(--font);
  font-size: 0.9375rem;
  line-height: 1.5;
  transition: border-color 0.15s, box-shadow 0.15s;
  appearance: none;
  -webkit-appearance: none;
}

.form-input::placeholder,
.form-textarea::placeholder {
  color: var(--text-muted);
}

.form-input:focus,
.form-select:focus,
.form-textarea:focus {
  outline: none;
  border-color: var(--accent);
  box-shadow: 0 0 0 3px var(--accent-subtle);
}

.form-input.is-invalid,
.form-select.is-invalid {
  border-color: var(--danger);
}

.form-input.is-invalid:focus,
.form-select.is-invalid:focus {
  box-shadow: 0 0 0 3px var(--danger-subtle);
}

.form-hint {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* OTP input — large digits */
.otp-input {
  text-align: center;
  font-size: 1.75rem;
  font-family: var(--font-mono);
  letter-spacing: 0.35em;
  padding: 0.75rem 1rem;
}

/* ── Alerts ─────────────────────────────────────────────────── */
.alert {
  display: flex;
  align-items: flex-start;
  gap: 0.625rem;
  padding: 0.75rem 1rem;
  border-radius: var(--radius-md);
  border: 1px solid transparent;
  font-size: 0.875rem;
  line-height: 1.5;
}

.alert-error {
  background: var(--danger-subtle);
  border-color: rgba(248, 81, 73, 0.3);
  color: #ff7b72;
}

.alert-success {
  background: var(--success-subtle);
  border-color: rgba(63, 185, 80, 0.3);
  color: #7ee787;
}

.alert-warning {
  background: var(--warning-subtle);
  border-color: rgba(210, 153, 34, 0.3);
  color: #e3b341;
}

.alert-info {
  background: var(--accent-subtle);
  border-color: rgba(47, 129, 247, 0.3);
  color: var(--accent-hover);
}

.alert-icon {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  margin-top: 2px;
}

/* ── Cards ──────────────────────────────────────────────────── */
.card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  overflow: hidden;
}

.card-header {
  padding: 1rem 1.25rem;
  border-bottom: 1px solid var(--border-subtle);
  display: flex;
  align-items: center;
  justify-content: space-between;
}

.card-body {
  padding: 1.25rem;
}

.card-footer {
  padding: 0.875rem 1.25rem;
  border-top: 1px solid var(--border-subtle);
  background: var(--bg-elevated);
}

/* Stat card */
.stat-card {
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  display: flex;
  flex-direction: column;
  gap: 0.5rem;
}

.stat-card .stat-label {
  font-size: 0.8125rem;
  color: var(--text-muted);
  font-weight: 500;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.stat-card .stat-value {
  font-size: 1.75rem;
  font-weight: 700;
  color: var(--text-primary);
  line-height: 1;
}

.stat-card .stat-sub {
  font-size: 0.8125rem;
  color: var(--text-secondary);
}

/* ── Badges ─────────────────────────────────────────────────── */
.badge {
  display: inline-flex;
  align-items: center;
  padding: 0.2rem 0.5rem;
  border-radius: 20px;
  font-size: 0.75rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  line-height: 1;
}

.badge-draft    { background: var(--bg-elevated);            color: var(--text-secondary); }
.badge-sent     { background: var(--accent-subtle);          color: var(--accent-hover); }
.badge-paid     { background: var(--success-subtle);         color: var(--success); }
.badge-overdue  { background: var(--danger-subtle);          color: var(--danger); }
.badge-partial  { background: rgba(124,58,237,0.25);         color: #c4b5fd; }
.badge-void     { background: var(--bg-elevated);            color: var(--text-muted); }

/* ── Tables ─────────────────────────────────────────────────── */
.table-wrap {
  overflow-x: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

thead {
  background: var(--bg-elevated);
}

thead th {
  padding: 0.625rem 1rem;
  text-align: left;
  font-size: 0.75rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.05em;
  color: var(--text-muted);
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 0.75rem 1rem;
  border-bottom: 1px solid var(--border-subtle);
  color: var(--text-secondary);
  font-size: 0.875rem;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--bg-elevated);
}

tbody td strong,
tbody td .text-primary-c {
  color: var(--text-primary);
}

/* ============================================================
   AUTHENTICATED APP SHELL
   ============================================================ */

/* ── Top bar ────────────────────────────────────────────────── */
.topbar {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  height: var(--topbar-h);
  background: var(--bg-surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  padding: 0 1.25rem;
  gap: 1rem;
  z-index: 100;
}

.topbar-brand {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  font-size: 1.125rem;
  font-weight: 700;
  color: var(--text-primary);
  text-decoration: none;
  width: var(--sidebar-w);
  flex-shrink: 0;
}

.topbar-brand:hover {
  color: var(--accent-hover);
  text-decoration: none;
}

.brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  background: var(--accent);
  border-radius: 7px;
  font-size: 0.875rem;
  font-weight: 800;
  color: #fff;
  flex-shrink: 0;
}

.topbar-spacer {
  flex: 1;
}

.topbar-actions {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

.topbar-user {
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0.25rem 0.625rem;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.875rem;
}

.avatar {
  width: 28px;
  height: 28px;
  background: var(--accent-subtle);
  border: 1px solid var(--border);
  border-radius: 50%;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  font-size: 0.75rem;
  font-weight: 600;
  color: var(--accent-hover);
  flex-shrink: 0;
}

/* ── Hamburger ──────────────────────────────────────────────── */
.hamburger {
  display: none;
  flex-direction: column;
  gap: 5px;
  cursor: pointer;
  padding: 0.5rem;
  background: none;
  border: none;
}

.hamburger span {
  display: block;
  width: 22px;
  height: 2px;
  background: var(--text-secondary);
  border-radius: 2px;
  transition: all 0.2s;
}

/* ── Sidebar overlay ────────────────────────────────────────── */
.sidebar-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.4);
  z-index: 89;
}

/* ── Sidebar ────────────────────────────────────────────────── */
.sidebar {
  position: fixed;
  top: var(--topbar-h);
  left: 0;
  bottom: 0;
  width: var(--sidebar-w);
  background: var(--bg-surface);
  border-right: 1px solid var(--border);
  padding: 1rem 0;
  overflow-y: auto;
  z-index: 90;
  transition: transform 0.25s ease;
}

.nav-section {
  padding: 0 0.75rem;
  margin-bottom: 0.25rem;
}

.nav-section-label {
  font-size: 0.6875rem;
  font-weight: 600;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 0.75rem 0.75rem 0.375rem;
}

.nav-link {
  display: flex;
  align-items: center;
  gap: 0.625rem;
  padding: 0.5rem 0.75rem;
  border-radius: var(--radius-md);
  color: var(--text-secondary);
  font-size: 0.875rem;
  font-weight: 500;
  text-decoration: none;
  transition: background 0.1s, color 0.1s;
  margin-bottom: 2px;
}

.nav-link:hover {
  background: var(--bg-elevated);
  color: var(--text-primary);
  text-decoration: none;
}

.nav-link.active {
  background: var(--accent-subtle);
  color: var(--accent-hover);
}

.nav-icon {
  width: 16px;
  height: 16px;
  flex-shrink: 0;
  opacity: 0.8;
}

.nav-link.active .nav-icon {
  opacity: 1;
}

.nav-divider {
  height: 1px;
  background: var(--border-subtle);
  margin: 0.5rem 1rem;
}

/* ── Main content ───────────────────────────────────────────── */
.main {
  margin-left: var(--sidebar-w);
  margin-top: var(--topbar-h);
  min-height: calc(100vh - var(--topbar-h));
  padding: 2rem;
}

.page-header {
  margin-bottom: 1.75rem;
}

.page-title {
  font-size: 1.5rem;
  font-weight: 700;
  color: var(--text-primary);
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 0.875rem;
  margin-top: 0.25rem;
}

/* Grid layouts */
.grid-4 {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  gap: 1rem;
}

.grid-3 {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 1rem;
}

.grid-2 {
  display: grid;
  grid-template-columns: repeat(2, 1fr);
  gap: 1rem;
}

@media (max-width: 1200px) {
  .grid-4 { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 768px) {
  .grid-4,
  .grid-3,
  .grid-2 { grid-template-columns: 1fr; }

  .hamburger { display: flex; }

  .topbar-brand { width: auto; }

  .sidebar { transform: translateX(-100%); }
  .sidebar.open { transform: translateX(0); }

  .sidebar-overlay.open { display: block; }

  .main { margin-left: 0; }
}

/* ── Kanban cards ───────────────────────────────────────────── */
.kanban-card {
  display: block;
  text-decoration: none;
  background: var(--bg-surface);
  border: 1px solid var(--border-subtle);
  border-radius: var(--radius-md);
  padding: 0.875rem 1rem;
  transition: border-color 0.15s;
  border-left-width: 3px;
}
.kanban-card:hover { border-color: var(--border); }

[data-status="enquiry"]           { border-left-color: var(--text-muted); }
[data-status="confirmed"]         { border-left-color: var(--accent); }
[data-status="in_progress"]       { border-left-color: #c4b5fd; }
[data-status="in_revision"]       { border-left-color: var(--warning); }
[data-status="awaiting_feedback"] { border-left-color: #e3b341; }
[data-status="delivered"]         { border-left-color: #38bdf8; }
[data-status="invoiced"]          { border-left-color: var(--success); }
[data-status="done"]              { border-left-color: var(--border); }

/* ============================================================
   AUTH PAGES (login, verify)
   ============================================================ */

.auth-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  padding: 1.5rem;
  background: var(--bg-base);
  /* subtle dot-grid texture */
  background-image: radial-gradient(var(--border-subtle) 1px, transparent 1px);
  background-size: 24px 24px;
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg-surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  box-shadow: var(--shadow-lg);
  overflow: hidden;
}

.auth-header {
  padding: 2rem 2rem 1.5rem;
  text-align: center;
  border-bottom: 1px solid var(--border-subtle);
}

.auth-brand {
  display: inline-flex;
  align-items: center;
  gap: 0.625rem;
  font-size: 1.375rem;
  font-weight: 800;
  color: var(--text-primary);
  text-decoration: none;
  margin-bottom: 1.25rem;
}

.auth-brand:hover { text-decoration: none; color: var(--text-primary); }

.auth-brand-mark {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 36px;
  height: 36px;
  background: var(--accent);
  border-radius: 9px;
  font-size: 1rem;
  font-weight: 900;
  color: #fff;
}

.auth-title {
  font-size: 1.125rem;
  font-weight: 600;
  color: var(--text-primary);
  margin-bottom: 0.25rem;
}

.auth-subtitle {
  font-size: 0.875rem;
  color: var(--text-muted);
}

.auth-body {
  padding: 1.75rem 2rem;
}

.auth-footer {
  padding: 1rem 2rem;
  border-top: 1px solid var(--border-subtle);
  text-align: center;
  background: var(--bg-elevated);
}

.auth-footer p {
  font-size: 0.8125rem;
  color: var(--text-muted);
}

/* Stacked form spacing inside auth card */
.auth-body .form-group + .form-group {
  margin-top: 1rem;
}

.auth-body .btn-block {
  margin-top: 1.5rem;
}

/* ── Light theme button overrides ───────────────────────────── */
[data-theme="light"] .btn-primary {
  background: #2f81f7;
  color: #ffffff !important;
  border-color: #2f81f7;
}

[data-theme="light"] .btn-primary:hover:not(:disabled) {
  background: #0969da;
  border-color: #0969da;
  color: #ffffff !important;
}

[data-theme="light"] .btn-secondary {
  background: #e8eaed;
  color: #1f2328 !important;
  border-color: #d0d7de;
}

[data-theme="light"] .btn-ghost {
  color: #636c76 !important;
}

[data-theme="light"] .btn-ghost:hover:not(:disabled) {
  background: #e8eaed;
  color: #1f2328 !important;
}

/* Logout form in topbar */
.logout-form {
  display: inline;
  margin: 0;
  padding: 0;
}
