/* Reypub ERP - application styles */
:root {
  --brand: #1e3a8a;
  --brand-2: #2563eb;
  --bg: #f1f5f9;
  --card: #ffffff;
  --text: #1f2937;
  --muted: #6b7280;
  --line: #e5e7eb;
  --good: #15803d;
  --bad: #b91c1c;
  --warn: #b45309;
  --side: #0f172a;
}
* { box-sizing: border-box; }
html, body { margin: 0; padding: 0; }
body { font-family: Inter, Arial, Helvetica, sans-serif; background: var(--bg); color: var(--text); font-size: 14px; }
a { color: var(--brand-2); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 22px; margin: 0; }
h3 { font-size: 15px; margin: 0 0 10px; color: var(--brand); }
p { margin: 6px 0; }
.hidden { display: none !important; }
.muted { color: var(--muted); }
.small { font-size: 12px; }
.center { text-align: center; }
.r { text-align: right; }
.nowrap { white-space: nowrap; }
.pos { color: var(--good); font-weight: 600; }
.neg { color: var(--bad); font-weight: 600; }
.bad { color: var(--bad); }
.warn { color: var(--warn); }
.good { color: var(--good); }

/* ---------- auth ---------- */
.auth-wrap { min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;
  background: linear-gradient(135deg, #1e3a8a, #0f172a); }
.auth-card { background: #fff; width: 100%; max-width: 420px; border-radius: 14px; padding: 28px; box-shadow: 0 20px 50px rgba(0,0,0,.35); }
.auth-brand { display: flex; gap: 12px; align-items: center; margin-bottom: 18px; }
.auth-brand h1 { color: var(--brand); }
.auth-brand small { color: var(--muted); }
.logo-mark { width: 46px; height: 46px; border-radius: 12px; background: var(--brand); color: #fff; display: grid; place-items: center; font-size: 24px; font-weight: 800; }
.stack { display: flex; flex-direction: column; gap: 12px; }
.stack label { display: flex; flex-direction: column; gap: 4px; font-weight: 600; font-size: 13px; }
.question { background: #eff6ff; padding: 10px; border-radius: 8px; font-weight: 600; }
.auth-card .link { margin-top: 2px; }

/* ---------- inputs & buttons ---------- */
input, select, textarea { font: inherit; padding: 8px 10px; border: 1px solid #cbd5e1; border-radius: 7px; background: #fff; color: var(--text); width: 100%; }
input[type=checkbox] { width: auto; }
input:focus, select:focus, textarea:focus { outline: 2px solid #93c5fd; border-color: var(--brand-2); }
textarea { resize: vertical; }
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 8px 14px; border: 1px solid #cbd5e1; background: #fff; color: var(--text);
  border-radius: 7px; cursor: pointer; font: inherit; font-weight: 600; white-space: nowrap; }
.btn:hover { background: #f8fafc; text-decoration: none; }
.btn:disabled { opacity: .6; cursor: default; }
.btn.primary { background: var(--brand-2); border-color: var(--brand-2); color: #fff; }
.btn.primary:hover { background: #1d4ed8; }
.btn.ghost { background: transparent; }
.btn.danger { color: var(--bad); border-color: #fecaca; }
.btn.danger:hover { background: #fef2f2; }
.btn.small { padding: 4px 9px; font-size: 12px; }
.btn.block { width: 100%; justify-content: center; }
.link { background: none; border: 0; color: var(--brand-2); cursor: pointer; padding: 0; font: inherit; text-align: left; }
.icon-btn { background: none; border: 0; font-size: 22px; line-height: 1; cursor: pointer; color: var(--muted); padding: 0 6px; }
.form-error { color: var(--bad); font-size: 13px; min-height: 0; }
.form-error:empty { display: none; }

/* ---------- app shell ---------- */
.app { display: flex; min-height: 100vh; }
.sidebar { width: 230px; background: var(--side); color: #cbd5e1; padding: 16px 10px; position: sticky; top: 0; height: 100vh; overflow-y: auto; flex-shrink: 0; }
.sidebar .brand { display: flex; gap: 10px; align-items: center; padding: 6px 8px 16px; border-bottom: 1px solid #1e293b; margin-bottom: 10px; }
.sidebar .brand img { max-height: 38px; max-width: 120px; background: #fff; border-radius: 6px; padding: 2px; }
.sidebar .brand strong { color: #fff; display: block; }
.sidebar .brand small { color: #94a3b8; font-size: 11px; }
.sidebar nav { display: flex; flex-direction: column; gap: 2px; }
.sidebar nav a { color: #cbd5e1; padding: 8px 10px; border-radius: 7px; font-size: 13px; }
.sidebar nav a:hover { background: #1e293b; text-decoration: none; color: #fff; }
.sidebar nav a.active { background: var(--brand-2); color: #fff; }
.main { flex: 1; min-width: 0; display: flex; flex-direction: column; }
.topbar { display: flex; justify-content: space-between; align-items: center; padding: 10px 24px; background: #fff; border-bottom: 1px solid var(--line); position: sticky; top: 0; z-index: 5; }
.content { padding: 0; }
.page { padding: 22px 24px 40px; max-width: 1400px; }
.page-head { display: flex; justify-content: space-between; align-items: center; gap: 12px; flex-wrap: wrap; margin-bottom: 16px; }
.page-head .actions { display: flex; gap: 8px; flex-wrap: wrap; }
.actions { display: flex; gap: 8px; flex-wrap: wrap; align-items: center; }
.toolbar { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; margin: 10px 0; }
.toolbar select { width: auto; }
.toolbar input[type=date] { width: auto; }
.search { max-width: 340px; }

/* ---------- cards & grid ---------- */
.card { background: var(--card); border: 1px solid var(--line); border-radius: 12px; padding: 16px 18px; margin-bottom: 16px; box-shadow: 0 1px 2px rgba(0,0,0,.04); }
.card.error { color: var(--bad); }
.grid-2 { display: grid; grid-template-columns: repeat(auto-fit, minmax(420px, 1fr)); gap: 16px; }
.grid-2 > .card { margin-bottom: 0; }
.kpi-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(190px, 1fr)); gap: 12px; margin-bottom: 16px; }
.kpi-grid.compact { grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); margin-bottom: 0; }
.kpi { background: var(--card); border: 1px solid var(--line); border-left: 4px solid #94a3b8; border-radius: 10px; padding: 12px 14px; }
.kpi span { display: block; font-size: 12px; color: var(--muted); margin-bottom: 4px; }
.kpi strong { font-size: 17px; }
.kpi.good { border-left-color: var(--good); }
.kpi.bad { border-left-color: var(--bad); }
.kpi.warn { border-left-color: #f59e0b; }
.chart-box { position: relative; height: 280px; }
.alerts { list-style: none; padding: 0; margin: 0; display: flex; flex-direction: column; gap: 8px; max-height: 340px; overflow-y: auto; }
.alert { padding: 9px 12px; border-radius: 8px; font-size: 13px; border: 1px solid transparent; }
.alert a { color: inherit; font-weight: 600; }
.alert.danger { background: #fef2f2; border-color: #fecaca; color: #7f1d1d; }
.alert.warning { background: #fffbeb; border-color: #fde68a; color: #78350f; }
.alert.info { background: #eff6ff; border-color: #bfdbfe; color: #1e3a8a; }
.alert.success { background: #f0fdf4; border-color: #bbf7d0; color: #14532d; }

/* ---------- tables ---------- */
.table-wrap { overflow-x: auto; background: var(--card); border: 1px solid var(--line); border-radius: 10px; margin-bottom: 16px; }
table { width: 100%; border-collapse: collapse; }
th, td { padding: 9px 10px; border-bottom: 1px solid var(--line); text-align: left; vertical-align: top; font-size: 13px; }
th { background: #f8fafc; font-size: 11px; text-transform: uppercase; letter-spacing: .03em; color: #475569; position: sticky; top: 0; }
tbody tr:hover { background: #f8fafc; }
.table-wrap table th:last-child, .table-wrap table td:last-child { white-space: nowrap; }
td.r, th.r { text-align: right; }
table.totals { width: 340px; margin-left: auto; background: transparent; border: 0; }
table.totals td { border: 0; padding: 5px 8px; }
table.totals tr.grand td { font-weight: 700; font-size: 15px; border-top: 2px solid var(--brand); }
table.items input { padding: 6px 8px; }
table.items input.n { width: 110px; text-align: right; }
.badge { display: inline-block; padding: 2px 9px; border-radius: 999px; font-size: 11px; font-weight: 600; background: #e2e8f0; color: #334155; text-transform: capitalize; }
.b-active, .b-paid, .b-completed, .b-open-, .b-good { background: #dcfce7; color: #166534; }
.b-open { background: #dbeafe; color: #1e40af; }
.b-restricted, .b-unpaid, .b-expired, .b-cancelled, .b-inactive { background: #fee2e2; color: #991b1b; }
.b-lead, .b-pending { background: #fef3c7; color: #92400e; }

/* ---------- misc components ---------- */
.domain-box { display: inline-flex; gap: 8px; align-items: center; padding: 10px 14px; border: 1px dashed var(--brand-2); border-radius: 10px; background: #eff6ff; font-weight: 600; margin: 4px 0 10px; }
.domain-box small { font-weight: 400; color: var(--muted); }
.readme, .pre { white-space: pre-wrap; font-family: inherit; background: #f8fafc; border: 1px solid var(--line); border-radius: 8px; padding: 10px; margin: 0; min-height: 60px; font-size: 13px; }
.logo-row { display: flex; gap: 16px; align-items: center; }
.logo-row img { max-height: 80px; max-width: 220px; border: 1px solid var(--line); border-radius: 8px; padding: 6px; background: #fff; }
.toast { position: fixed; bottom: 22px; right: 22px; background: #111827; color: #fff; padding: 12px 18px; border-radius: 9px; box-shadow: 0 10px 30px rgba(0,0,0,.25); z-index: 100; max-width: 420px; }
.toast.err { background: var(--bad); }

/* ---------- modal & forms ---------- */
.modal-bg { position: fixed; inset: 0; background: rgba(15,23,42,.55); display: flex; align-items: flex-start; justify-content: center; padding: 40px 14px; z-index: 50; overflow-y: auto; }
.modal { background: #fff; border-radius: 12px; width: 100%; max-width: 640px; box-shadow: 0 25px 60px rgba(0,0,0,.3); }
.modal.wide { max-width: 980px; }
.modal-head { display: flex; justify-content: space-between; align-items: center; padding: 14px 18px; border-bottom: 1px solid var(--line); }
.modal-head h3 { margin: 0; font-size: 17px; }
.modal-body { padding: 16px 18px 18px; }
.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 12px 14px; }
.form-grid .full { grid-column: 1 / -1; }
.field { display: flex; flex-direction: column; gap: 4px; font-size: 13px; font-weight: 600; color: #334155; }
.field.check { flex-direction: row; align-items: center; gap: 8px; font-weight: 500; }
.form-actions { display: flex; justify-content: flex-end; gap: 8px; margin-top: 4px; }
.form-grid h3 { grid-column: 1 / -1; margin-top: 8px; border-bottom: 1px solid var(--line); padding-bottom: 4px; }

@media (max-width: 900px) {
  .app { flex-direction: column; }
  .sidebar { width: 100%; height: auto; position: static; }
  .sidebar nav { flex-direction: row; flex-wrap: wrap; }
  .grid-2 { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .page { padding: 16px; }
}

@media print {
  .sidebar, .topbar, .no-print { display: none !important; }
}
