/* ============================================
   KG3N Invoices - app stylesheet
   Brand tokens mirror kg3n.com (2026 refresh)
   ============================================ */

*, *::before, *::after { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }

:root {
  /* Brand palette */
  --primary: #0c1638;
  --accent-start: #1d4ed8;
  --accent-end: #06b6d4;
  --gradient-accent: linear-gradient(135deg, var(--accent-start), var(--accent-end));

  /* Surfaces */
  --bg: #f6faff;
  --bg-alt: #f0f7ff;
  --surface: #ffffff;
  --surface-hover: color-mix(in srgb, var(--accent-start) 4%, white);

  /* Text */
  --text: #1e3a5f;
  --text-light: #4a6d8c;
  --text-heading: #0c1638;
  --border: #d0e2f0;
  --border-strong: color-mix(in srgb, var(--accent-start) 18%, var(--border));

  /* Status accents */
  --ok:        #0f6e56;
  --ok-bg:     #d6f0e3;
  --warn:      #7a5800;
  --warn-bg:   #fff4cc;
  --info:      #0a4a7a;
  --info-bg:   #cfe6ff;
  --danger:    #7a0a0a;
  --danger-bg: #ffd6d2;
  --muted:     #4a6d8c;
  --muted-bg:  #eef2f7;

  /* Radius scale */
  --radius-xs: 8px;
  --radius-sm: 12px;
  --radius-md: 16px;
  --radius: 22px;
  --radius-lg: 28px;
  --radius-full: 999px;

  /* Shadows */
  --shadow-sm: 0 1px 2px rgba(12,22,56,.05), 0 2px 6px rgba(12,22,56,.06);
  --shadow:    0 1px 2px rgba(12,22,56,.05), 0 4px 10px rgba(12,22,56,.06), 0 12px 24px rgba(12,22,56,.05);
  --shadow-md: 0 2px 4px rgba(12,22,56,.06), 0 8px 20px rgba(12,22,56,.08), 0 20px 40px rgba(12,22,56,.06);
  --shadow-glow-accent: 0 0 0 1px rgba(29,78,216,.08), 0 8px 24px rgba(29,78,216,.22);
  --focus-ring: 0 0 0 3px rgba(29,78,216,.28);

  /* Motion */
  --duration-fast: 150ms;
  --duration: 250ms;
  --ease-standard: cubic-bezier(0.2, 0.8, 0.2, 1);
  --transition: var(--duration) var(--ease-standard);
}

body {
  font-family: 'DM Sans', system-ui, -apple-system, sans-serif;
  font-size: 14.5px;
  line-height: 1.55;
  color: var(--text);
  background:
    radial-gradient(1200px 600px at 80% -10%, rgba(6,182,212,.07), transparent 60%),
    radial-gradient(900px 500px at -10% 110%, rgba(29,78,216,.06), transparent 55%),
    var(--bg);
  background-attachment: fixed;
  -webkit-font-smoothing: antialiased;
  -moz-osx-font-smoothing: grayscale;
}

a { color: var(--accent-start); text-decoration: none; transition: color var(--transition); }
a:hover { color: var(--accent-end); }

::selection { background: color-mix(in srgb, var(--accent-end) 35%, transparent); color: var(--text-heading); }

/* ---------- Top bar ---------- */
.topbar {
  position: sticky; top: 0; z-index: 30;
  display: flex; align-items: flex-end; gap: 28px;
  padding: 16px 28px 8px;
  background: rgba(255,255,255,.78);
  backdrop-filter: saturate(180%) blur(14px);
  -webkit-backdrop-filter: saturate(180%) blur(14px);
  border-bottom: 1px solid color-mix(in srgb, var(--border) 70%, transparent);
}
.topbar .brand {
  display: flex; align-items: center; gap: 10px;
  font-weight: 700; letter-spacing: .2px; color: var(--text-heading);
}
.topbar .brand img { height: 72px; width: auto; display: block; }

.topbar nav { display: flex; gap: 4px; align-self: flex-end; padding-bottom: 4px; }
.topbar nav a {
  position: relative;
  color: var(--text);
  font-weight: 500;
  padding: 6px 14px;
  border-radius: var(--radius-sm);
  transition: var(--transition);
}
.topbar nav a:hover { color: var(--accent-start); background: var(--surface-hover); }
.topbar nav a.active { color: var(--text-heading); }
.topbar nav a.active::after {
  content: '';
  position: absolute; left: 14px; right: 14px; bottom: 2px;
  height: 2px; border-radius: 2px;
  background: var(--gradient-accent);
}
.topbar .spacer { flex: 1; }
.topbar .user {
  display: flex; align-items: center; gap: 10px;
  align-self: flex-end; padding-bottom: 4px;
  color: var(--text-light); font-size: 13px;
}
.topbar .user .who {
  display: inline-flex; align-items: center; gap: 8px;
  padding: 6px 12px;
  background: var(--bg-alt);
  border-radius: var(--radius-full);
}
.topbar .user .who::before {
  content: ''; width: 7px; height: 7px; border-radius: 50%;
  background: var(--accent-end); box-shadow: 0 0 0 3px rgba(6,182,212,.18);
}

/* ---------- Layout ---------- */
.container { max-width: 1180px; margin: 0 auto; padding: 28px 24px 64px; }

h1 {
  margin: 0 0 18px; font-size: 26px; font-weight: 600;
  color: var(--text-heading); letter-spacing: -0.01em;
}
h1 small {
  display: inline-block; margin-left: 8px;
  font-size: 13px; font-weight: 500; color: var(--text-light);
}

h3 { color: var(--text-heading); font-weight: 600; }

/* ---------- Cards ---------- */
.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px;
  margin-bottom: 18px;
  box-shadow: var(--shadow-sm);
  transition: var(--transition);
}
.card:hover { box-shadow: var(--shadow); }
.card.tight { padding: 0; overflow: hidden; }

/* ---------- Stat cards ---------- */
.stat-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(min(220px, 100%), 1fr));
  gap: 16px;
  margin-bottom: 22px;
}
.stat {
  position: relative;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 22px 22px 20px;
  box-shadow: var(--shadow-sm);
  overflow: hidden;
}
.stat::before {
  content: ''; position: absolute; inset: 0;
  background: var(--gradient-accent);
  opacity: 0; transition: opacity var(--transition);
}
.stat::after {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 3px;
  background: var(--gradient-accent);
  opacity: .9;
}
.stat .label {
  font-size: 11px; letter-spacing: .12em; text-transform: uppercase;
  color: var(--text-light); font-weight: 600;
}
.stat .value {
  font-family: 'Space Mono', ui-monospace, monospace;
  font-size: 28px; font-weight: 700;
  color: var(--text-heading);
  margin-top: 8px; letter-spacing: -0.01em;
}
.stat .meta { font-size: 12px; color: var(--text-light); margin-top: 6px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  padding: 10px 18px;
  font-family: inherit; font-size: 13.5px; font-weight: 600;
  color: #fff; background: var(--gradient-accent); border: none;
  border-radius: var(--radius-sm);
  cursor: pointer; text-decoration: none; white-space: nowrap;
  box-shadow: 0 2px 8px rgba(29,78,216,.22);
  transition:
    transform var(--duration-fast) var(--ease-standard),
    box-shadow var(--transition),
    background var(--transition);
}
.btn:hover { transform: translateY(-1px); box-shadow: 0 6px 16px rgba(29,78,216,.35), var(--shadow-glow-accent); color: #fff; }
.btn:active { transform: translateY(0); }
.btn:focus-visible { outline: none; box-shadow: var(--focus-ring); }

.btn.secondary {
  background: var(--surface); color: var(--text-heading);
  border: 1.5px solid var(--border);
  box-shadow: none;
}
.btn.secondary:hover {
  background: var(--surface-hover); color: var(--accent-start);
  border-color: var(--accent-start);
  box-shadow: var(--shadow-sm);
}

.btn.green {
  background: linear-gradient(135deg, #0f6e56, #14a085);
  box-shadow: 0 2px 8px rgba(15,110,86,.25);
}
.btn.green:hover { box-shadow: 0 6px 16px rgba(15,110,86,.35); }

.btn.danger {
  background: linear-gradient(135deg, #be3b1d, #d6573a);
  box-shadow: 0 2px 8px rgba(190,59,29,.25);
}

/* ---------- Pills (status) ---------- */
.pill {
  display: inline-flex; align-items: center; gap: 6px;
  padding: 4px 10px; border-radius: var(--radius-full);
  font-size: 11px; font-weight: 700;
  text-transform: uppercase; letter-spacing: .08em;
  background: var(--muted-bg); color: var(--muted);
}
.pill::before {
  content: ''; width: 6px; height: 6px; border-radius: 50%;
  background: currentColor; opacity: .8;
}
.pill.draft     { background: var(--muted-bg);  color: var(--muted); }
.pill.scheduled { background: var(--warn-bg);   color: var(--warn); }
.pill.sent      { background: var(--info-bg);   color: var(--info); }
.pill.paid      { background: var(--ok-bg);     color: var(--ok); }
.pill.overdue   { background: var(--danger-bg); color: var(--danger); }
.pill.cancelled { background: var(--muted-bg);  color: var(--muted); opacity: .7; }

.pill.recurrence { background: var(--bg-alt); color: var(--accent-start); }
.pill.recurrence::before { background: var(--accent-end); }

/* ---------- Tables ---------- */
table { width: 100%; border-collapse: separate; border-spacing: 0; font-size: 13.5px; }
th {
  text-align: left; padding: 12px 16px;
  background: var(--bg-alt);
  font-size: 10.5px; text-transform: uppercase; letter-spacing: .1em; font-weight: 700;
  color: var(--text-light);
  border-bottom: 1px solid var(--border);
}
td {
  padding: 14px 16px;
  border-bottom: 1px solid color-mix(in srgb, var(--border) 60%, transparent);
  vertical-align: top;
}
tbody tr { transition: background var(--transition); }
tbody tr:hover { background: var(--surface-hover); }
tbody tr:last-child td { border-bottom: none; }

td .mono, .mono {
  font-family: 'Space Mono', ui-monospace, monospace;
  font-size: 12.5px; color: var(--text-heading);
}
.right { text-align: right; }
.muted { color: var(--text-light); font-size: 12.5px; }

/* ---------- Forms ---------- */
label {
  display: block;
  font-size: 12px; text-transform: uppercase; letter-spacing: .08em; font-weight: 600;
  color: var(--text-light); margin: 14px 0 6px;
}
input, select, textarea {
  width: 100%;
  font: inherit; font-size: 14px;
  padding: 10px 12px;
  background: var(--surface); color: var(--text);
  border: 1.5px solid var(--border); border-radius: var(--radius-sm);
  transition: var(--transition);
}
input:hover, select:hover, textarea:hover { border-color: var(--border-strong); }
input:focus, select:focus, textarea:focus {
  outline: none; border-color: var(--accent-start);
  box-shadow: var(--focus-ring);
}
textarea { resize: vertical; min-height: 70px; }

.row { display: flex; gap: 14px; flex-wrap: wrap; }
.row > * { flex: 1; min-width: 0; }

/* ---------- Flash ---------- */
.flash {
  padding: 12px 16px; border-radius: var(--radius-sm);
  margin-bottom: 14px; font-size: 13.5px; font-weight: 500;
  border-left: 3px solid currentColor;
}
.flash.ok  { background: var(--ok-bg);     color: var(--ok); }
.flash.err { background: var(--danger-bg); color: var(--danger); }

/* ---------- Login ---------- */
.login-wrap {
  min-height: calc(100vh - 60px);
  display: flex; align-items: center; justify-content: center;
  padding: 40px 20px;
}
.login-card {
  width: 100%; max-width: 400px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 36px 32px;
  box-shadow: var(--shadow-md);
  position: relative; overflow: hidden;
}
.login-card::before {
  content: ''; position: absolute; top: 0; left: 0; right: 0; height: 4px;
  background: var(--gradient-accent);
}
.login-card .brand-mark {
  display: flex; flex-direction: column; align-items: center; gap: 10px;
  margin-bottom: 26px;
}
.login-card .brand-mark img { height: 72px; width: auto; display: block; }
.login-card .brand-mark .console-label {
  color: var(--text-light); font-size: 11.5px;
  letter-spacing: .14em; text-transform: uppercase; font-weight: 600;
}
.login-card h1, .login-card .sub { text-align: center; }
.login-card h1 { font-size: 22px; margin: 0 0 4px; }
.login-card .sub { color: var(--text-light); font-size: 13.5px; margin: 0 0 22px; }

/* ---------- Action stack on invoice view ---------- */
.action-stack form, .action-stack a.btn { display: block; margin-bottom: 10px; width: 100%; }
.action-stack a.btn, .action-stack button.btn { width: 100%; }

/* ---------- Misc ---------- */
.hairline { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

.totals-box {
  text-align: right; font-size: 13.5px; margin-top: 12px;
  color: var(--text-light);
}
.totals-box .grand {
  font-family: 'Space Mono', ui-monospace, monospace;
  font-size: 22px; font-weight: 700;
  color: var(--text-heading);
  margin-top: 4px;
}

/* ---------- Empty state ---------- */
.empty {
  text-align: center; padding: 36px 20px; color: var(--text-light);
}
.empty a { font-weight: 600; }

/* ---------- Responsive ---------- */
@media (max-width: 720px) {
  .topbar { padding: 12px 16px; gap: 12px; flex-wrap: wrap; }
  .topbar nav a { padding: 6px 10px; }
  .container { padding: 20px 14px 48px; }
  .row { flex-direction: column; }
  .stat .value { font-size: 22px; }
}
