:root {
  --bg: #f7f7f9;
  --card: #ffffff;
  --ink: #1f2430;
  --muted: #4b5563;
  --line: #d4d7dd;
  --input-line: #a9afba;
  --accent: #2d3142;
  --accent-light: #33405c;
  --danger: #b3261e;
  --green: #166534;
  --green-bg: #dcfce7;
  --orange: #92400e;
  --orange-bg: #fef3c7;
  --radius: 10px;
}

* { box-sizing: border-box; }
body { margin: 0; font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif; background: var(--bg); color: var(--ink); padding: 24px; font-size: 16px; line-height: 1.45; }
.wrap { max-width: 1280px; margin: 0 auto; }

h1 { font-size: 26px; margin: 0 0 4px 0; }
h2 { font-size: 17px; margin: 0 0 14px 0; color: var(--accent); }
.sub { color: var(--muted); font-size: 16px; margin-bottom: 20px; }

.main-nav { display: flex; justify-content: space-between; align-items: center; margin-bottom: 24px; flex-wrap: wrap; gap: 10px; border-bottom: 1px solid var(--line); padding-bottom: 14px; }
.nav-logo { font-size: 17px; font-weight: 700; color: var(--ink); text-decoration: none; white-space: nowrap; }
.nav-links { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

.page-header { display: flex; justify-content: space-between; align-items: flex-start; margin-bottom: 4px; }

.card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 18px 20px; margin-bottom: 18px; }

.form-row { display: flex; gap: 10px; flex-wrap: wrap; align-items: flex-end; }
.field { display: flex; flex-direction: column; gap: 4px; flex: 1 1 140px; }
.field.wide { flex: 2 1 220px; }
.field.narrow { flex: 0 1 110px; }
.field.fixed { flex: 0 0 auto; }

label { font-size: 14px; color: var(--muted); font-weight: 500; }
input, select, textarea { padding: 8px 10px; border: 1px solid var(--input-line); border-radius: 7px; font-size: 16px; background: #fff; color: var(--ink); width: 100%; }
input:focus, select:focus, textarea:focus { outline: 2px solid var(--accent-light); outline-offset: -1px; border-color: var(--accent-light); }
textarea { resize: vertical; min-height: 60px; }

button, .btn { padding: 9px 16px; border: none; border-radius: 7px; background: var(--accent); color: #fff; font-size: 16px; cursor: pointer; text-decoration: none; display: inline-block; }
button:hover, .btn:hover { background: var(--accent-light); }
.btn-secondary { background: #fff; color: var(--accent); border: 1px solid var(--line); }
.btn-secondary:hover { background: #f0f0f2; }
.btn-danger { background: #fff; color: var(--danger); border: 1px solid #d99a94; padding: 6px 10px; font-size: 14px; }
.btn-danger:hover { background: #fbeceb; }
.btn-sm { padding: 6px 10px; font-size: 14px; }
.btn-green { background: var(--green); }
.btn-green:hover { background: #14532d; }

table { width: 100%; border-collapse: collapse; font-size: 15px; }
th, td { padding: 8px 10px; text-align: left; border-bottom: 1px solid var(--line); }
th { color: var(--muted); font-weight: 600; font-size: 14px; text-transform: uppercase; letter-spacing: 0.02em; }
tr:hover td { background: #fafafb; }
td.num, th.num { text-align: right; white-space: nowrap; }
td.actions { display: flex; gap: 6px; }

.toolbar { display: flex; justify-content: space-between; align-items: center; flex-wrap: wrap; gap: 10px; margin-bottom: 14px; }

.empty { color: var(--muted); text-align: center; padding: 30px 0; font-size: 16px; }

a.link { color: var(--accent-light); text-decoration: none; font-size: 15px; }
a.link:hover { text-decoration: underline; }
button.btn-link { background: none; border: none; padding: 0; cursor: pointer; color: var(--accent-light); font-size: 15px; font-family: inherit; }
button.btn-link:hover { text-decoration: underline; }

footer { text-align: center; color: var(--muted); font-size: 14px; margin-top: 24px; }

/* Status badges */
.badge { display: inline-block; padding: 2px 8px; border-radius: 12px; font-size: 13px; font-weight: 600; }
.badge-draft { background: var(--line); color: var(--muted); }
.badge-sent { background: var(--orange-bg); color: var(--orange); }
.badge-paid { background: var(--green-bg); color: var(--green); }
.badge-cancelled { background: #fee2e2; color: var(--danger); }

/* Stats grid */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 18px; }
.stat-card { background: var(--card); border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; }
.stat-card .stat-label { font-size: 13px; color: var(--muted); margin-bottom: 4px; }
.stat-card .stat-value { font-size: 20px; font-weight: 700; color: var(--accent); }
.stat-card.highlight { border-color: var(--accent); }
.stat-card.danger { border-color: var(--danger); }
.stat-card.danger .stat-value { color: var(--danger); }

/* Invoice items table */
.items-section { margin-top: 16px; }
.items-section table input, .items-section table select { padding: 6px 8px; font-size: 15px; }
.add-row-btn { margin-top: 8px; }

/* ARES lookup */
.ares-results { position: absolute; top: 100%; left: 0; right: 0; background: white; border: 1px solid var(--line); border-radius: 7px; box-shadow: 0 4px 12px rgba(0,0,0,.1); z-index: 100; max-height: 240px; overflow-y: auto; min-width: 320px; }
.ares-results li { list-style: none; padding: 8px 12px; cursor: pointer; font-size: 15px; border-bottom: 1px solid var(--line); }
.ares-results li:hover { background: var(--bg); }
.ares-results li:last-child { border-bottom: none; }
.ares-wrap { position: relative; }

/* Invoice detail */
.invoice-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 20px; }
.invoice-header-right { display: flex; flex-direction: column; gap: 10px; align-items: flex-end; }
.invoice-doc-links { display: flex; gap: 10px; align-items: center; flex-wrap: wrap; justify-content: flex-end; }
.invoice-doc-links button { background: none; border: none; padding: 0; color: var(--accent-light); font-size: 15px; cursor: pointer; font-family: inherit; }
.invoice-doc-links button:hover { text-decoration: underline; }
.invoice-status-btns { display: flex; gap: 6px; flex-wrap: wrap; justify-content: flex-end; }

/* Scoped button reset — higher specificity (0,1,1) beats base button (0,0,1) */
.invoice-status-btns button {
  background: #fff; color: var(--muted); border: 1px solid var(--line);
  padding: 4px 10px; font-size: 14px; border-radius: 5px;
  cursor: pointer; font-family: inherit; white-space: nowrap; display: inline-block;
}
.invoice-status-btns button:hover { background: #f5f5f7; color: var(--ink); border-color: #d1d5db; }
.invoice-status-btns button.is-green { color: var(--green); border-color: #bbf7d0; }
.invoice-status-btns button.is-green:hover { background: var(--green-bg); }
.invoice-status-btns button.is-red { color: var(--danger); border-color: #fecaca; }
.invoice-status-btns button.is-red:hover { background: #fef2f2; }
.totals-block { text-align: right; margin-top: 12px; }
.totals-block .total-line { padding: 3px 0; font-size: 16px; }
.totals-block .grand-total { font-size: 18px; font-weight: 700; color: var(--accent); margin-top: 6px; }

/* Alerts */
.alert { padding: 10px 14px; border-radius: 7px; font-size: 16px; margin-bottom: 14px; }
.alert-danger { background: #fee2e2; color: #991b1b; border: 1px solid #fca5a5; }
.alert-warn { background: var(--orange-bg); color: var(--orange); border: 1px solid #fcd34d; }
.alert-ok { background: var(--green-bg); color: var(--green); border: 1px solid #86efac; }

/* Form groups */
.form-group { display: flex; flex-direction: column; gap: 4px; margin-bottom: 12px; }
.form-group label { font-size: 14px; color: var(--muted); font-weight: 500; }

@media (max-width: 640px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .invoice-header { flex-direction: column; }
}
