:root {
  --green: #1f8a4c; --green-d: #176b3b; --green-l: #e8f5ee;
  --ink: #1d2530; --muted: #6b7684; --line: #d9dee4; --bg: #f4f5f8; --card: #fff;
  --red: #c62828; --red-l: #fdecea; --amber-l: #fff6e0; --blue-l: #e8f1fb;
  --radius: 6px; --topbar: 56px; --foot: 64px;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  font-size: 14px; color: var(--ink);
}
* { box-sizing: border-box; }
body { margin: 0; background: var(--bg); line-height: 1.45; }
a { color: var(--green-d); text-decoration: none; }
a:hover { text-decoration: underline; }
h1 { font-size: 1.5rem; margin: 0 0 1rem; font-weight: 600; }
h2 { font-size: 1.2rem; margin: 0 0 1rem; }
h3 { font-size: 1rem; margin: 1.25rem 0 .6rem; font-weight: 600; }
.hidden { display: none !important; }
.muted { color: var(--muted); } .small { font-size: .85rem; }
.req { color: var(--red); }
.hint { color: var(--muted); font-size: .82rem; margin: .25rem 0 .5rem; display: block; }
.num { text-align: right; }

/* Top bar */
.topbar { height: var(--topbar); background: #fff; border-bottom: 1px solid var(--line); display: flex; align-items: center; gap: 2rem; padding: 0 1.5rem; position: sticky; top: 0; z-index: 10; }
.brand { font-weight: 700; font-size: 1.15rem; color: var(--ink); letter-spacing: -.01em; }
.brand:hover { text-decoration: none; }
.brand-mark { display: inline-grid; place-items: center; width: 28px; height: 28px; border-radius: 50%; background: var(--green); color: #fff; margin-right: .3rem; }
.tld { color: var(--green); }
.topbar nav { display: flex; gap: .25rem; flex: 1; }
.topbar nav a { color: var(--muted); padding: .45rem .8rem; border-radius: var(--radius); font-weight: 500; }
.topbar nav a.active, .topbar nav a:hover { color: var(--ink); background: var(--bg); text-decoration: none; }
.logout { margin-left: .25rem; }
.plan-badge { margin-left: auto; padding: .25rem .7rem; border-radius: 999px; font-size: .8rem; font-weight: 700; background: var(--bg); color: var(--muted); border: 1px solid var(--line); white-space: nowrap; }
.plan-badge.pro { background: var(--green); color: #fff; border-color: var(--green); }
.plan-badge:hover { text-decoration: none; }

/* Plans */
.usage { display: flex; justify-content: space-between; gap: 1rem; flex-wrap: wrap; background: var(--green-l); border: 1px solid #b9e0c9; padding: .65rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.usage a { font-weight: 600; }
.plans { display: grid; grid-template-columns: repeat(2, minmax(0, 320px)); gap: 1.25rem; margin: 1.5rem 0; }
.plan { background: #fff; border: 1px solid var(--line); border-radius: 10px; padding: 1.5rem; position: relative; }
.plan.current { border: 2px solid var(--green); }
.plan h2 { margin-bottom: .25rem; }
.plan .price { font-size: 2rem; font-weight: 700; margin-bottom: 1rem; }
.plan .price span { font-size: .9rem; font-weight: 400; color: var(--muted); }
.plan ul { padding-left: 1.1rem; margin: 0 0 1.25rem; }
.plan li { margin-bottom: .35rem; }
.plan-tag { position: absolute; top: 1rem; right: 1rem; background: var(--green); color: #fff; font-size: .75rem; font-weight: 700; padding: .2rem .6rem; border-radius: 999px; }
.manage { display: flex; align-items: center; gap: 1rem; }
@media (max-width: 700px) { .plans { grid-template-columns: 1fr; } }

/* Controls */
label { display: block; font-weight: 500; margin-bottom: .75rem; font-size: .9rem; }
input[type=text], input[type=email], input[type=tel], input[type=number], input[type=date], input[type=search], select, textarea {
  display: block; width: 100%; margin-top: .3rem; padding: .5rem .6rem; border: 1px solid #b8c0ca; border-radius: 4px;
  font: inherit; font-weight: 400; background: #fff; color: var(--ink);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--green); outline-offset: -1px; border-color: var(--green); }
input.invalid, select.invalid { border-color: var(--red); background: var(--red-l); }
textarea { resize: vertical; }
input.num { text-align: right; }
input.inline, select.inline { display: inline-block; width: auto; margin: 0 .25rem; padding: .3rem .4rem; }
input.inline.num { width: 5.5rem; }
input.w-sm { display: inline-block; width: 5rem; margin: 0 .35rem; }
.check, .radio { font-weight: 400; display: flex; align-items: center; gap: .5rem; }
.check.inline { display: inline-flex; margin: 0 0 0 .75rem; }
.btn { display: inline-flex; align-items: center; justify-content: center; gap: .4rem; padding: .55rem 1.1rem; border: 1px solid #8d97a3; background: #fff; color: var(--ink);
  border-radius: 999px; font: inherit; font-weight: 600; cursor: pointer; }
.btn:hover { background: var(--bg); text-decoration: none; }
.btn-primary { background: var(--green); border-color: var(--green); color: #fff; }
.btn-primary:hover { background: var(--green-d); }
.btn-primary:disabled { opacity: .6; cursor: wait; }
.btn-sm { padding: .35rem .8rem; font-size: .85rem; }
.btn-lg { padding: .7rem 1.6rem; font-size: 1rem; }
.btn-block { width: 100%; }
.link { background: none; border: 0; padding: 0; color: var(--green-d); font: inherit; cursor: pointer; font-weight: 500; }
.link:hover { text-decoration: underline; }
.danger { color: var(--red); }
.icon-btn { background: none; border: 0; cursor: pointer; opacity: .55; font-size: 1rem; }
.icon-btn:hover { opacity: 1; }

/* Alerts */
.alert { padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: 1rem; }
.alert ul { margin: .4rem 0 0; padding-left: 1.2rem; }
.alert-error { background: var(--red-l); color: #8e1c1c; border: 1px solid #f3c1bd; }
.alert-info { background: var(--blue-l); color: #174a7c; }
.flash { margin: 1rem auto 0; max-width: 1200px; padding: .75rem 1rem; border-radius: var(--radius); }
.flash-success { background: var(--green-l); color: var(--green-d); border: 1px solid #b9e0c9; }
.flash-error { background: var(--red-l); color: #8e1c1c; }
.flash-warning { background: var(--amber-l); color: #7a5200; }

/* Pages */
.page { max-width: 1200px; margin: 0 auto; padding: 1.5rem; }
.page.narrow { max-width: 560px; }
.form-page { max-width: 980px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 1rem; margin-bottom: 1rem; flex-wrap: wrap; }
.page-head h1 { margin: 0; }
.row-end, .form-foot { display: flex; justify-content: flex-end; gap: .6rem; margin-top: 1rem; }
.form-foot { position: sticky; bottom: 0; background: var(--bg); padding: 1rem 0; border-top: 1px solid var(--line); }
.empty { background: #fff; border: 1px dashed var(--line); border-radius: var(--radius); padding: 3rem; text-align: center; color: var(--muted); }
.table-wrap { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); overflow-x: auto; }
table.list { width: 100%; border-collapse: collapse; }
table.list th { text-align: left; font-size: .78rem; text-transform: uppercase; letter-spacing: .03em; color: var(--muted); background: #fafbfc; }
table.list th, table.list td { padding: .7rem .9rem; border-bottom: 1px solid var(--line); vertical-align: top; }
table.list tr:last-child td { border-bottom: 0; }
.actions { white-space: nowrap; text-align: right; }
.actions form { display: inline; margin-left: .75rem; }
.tabs { display: flex; gap: .25rem; align-items: center; margin-bottom: 1rem; border-bottom: 1px solid var(--line); }
.tabs a { padding: .6rem 1rem; color: var(--muted); border-bottom: 3px solid transparent; font-weight: 600; }
.tabs a.active { color: var(--ink); border-color: var(--green); }
.tabs .search { margin-left: auto; width: 260px; }
.tabs .search input { margin: 0 0 .4rem; }
.panel { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 1rem 1.25rem; margin-bottom: 1rem; }
details.panel > summary { cursor: pointer; font-weight: 600; font-size: 1.05rem; list-style: none; display: flex; align-items: center; gap: .5rem; }
details.panel > summary::before { content: "›"; display: inline-block; transition: transform .15s; font-size: 1.3rem; line-height: 1; color: var(--muted); }
details.panel[open] > summary::before { transform: rotate(90deg); }
details.panel[open] > summary { margin-bottom: 1rem; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 1rem; }
.grid-4 { display: grid; grid-template-columns: 2fr 3fr 1fr 1.5fr; gap: 0 1rem; }
.grid-5 { display: grid; grid-template-columns: 1fr 2fr 2fr 2fr 1fr; gap: 0 1rem; }
.span-2 { grid-column: span 2; }
.seg { display: inline-flex; border: 1px solid #8d97a3; border-radius: 999px; overflow: hidden; }
.seg label { margin: 0; }
.seg input { display: none; }
.seg span { display: block; padding: .45rem 1.1rem; cursor: pointer; font-weight: 600; }
.seg input:checked + span { background: var(--green); color: #fff; }
.addr-preview { background: var(--bg); padding: .75rem 1rem; border-radius: var(--radius); font-family: inherit; white-space: pre-line; }
.logo-preview { max-height: 90px; max-width: 240px; border: 1px solid var(--line); padding: 4px; background: #fff; }

/* Auth */
body.auth { background: linear-gradient(160deg, #e8f5ee, #f4f5f8 60%); min-height: 100vh; }
.auth-card { max-width: 400px; margin: 10vh auto; background: #fff; padding: 2rem; border-radius: 12px; box-shadow: 0 8px 30px rgba(20, 40, 30, .1); }
.otp-input { font-size: 1.6rem; letter-spacing: .5em; text-align: center; font-family: ui-monospace, Menlo, monospace; }
.auth-links { display: flex; justify-content: space-between; margin-top: 1rem; }

/* Type picker / under construction */
.type-picker { background: #fff; padding: 1.5rem; border-radius: var(--radius); border: 1px solid var(--line); }
.construction { text-align: center; background: #fff; padding: 3rem 2rem; border-radius: var(--radius); border: 1px solid var(--line); }
.construction-icon { font-size: 3rem; }

/* ================= Recurring invoice editor ================= */
body.editor-page { overflow: hidden; }
body.editor-page .flash { position: absolute; top: calc(var(--topbar) + .5rem); left: 50%; transform: translateX(-50%); z-index: 20; margin: 0; }
.editor { display: grid; grid-template-columns: minmax(0, 1fr) 380px; grid-template-rows: minmax(0, 1fr) var(--foot); height: calc(100vh - var(--topbar)); }
.editor-main { overflow-y: auto; padding: 1.5rem; }
.editor-side { overflow-y: auto; background: #fff; border-left: 1px solid var(--line); padding: 1.5rem; }
.editor-foot { grid-column: 1 / -1; display: flex; align-items: center; gap: 1rem; padding: 0 1.5rem; background: #2b3440; }
.editor-foot .btn:not(.btn-primary) { background: transparent; color: #fff; border-color: #8d97a3; }
.editor-foot .btn-primary { margin-left: auto; }
.status { color: #cfd6dd; font-size: .9rem; } .status.error { color: #ffb4ab; }

.inv-sheet { background: #fff; border: 1px solid var(--line); border-radius: var(--radius); padding: 2rem; max-width: 980px; margin: 0 auto; box-shadow: 0 1px 3px rgba(0,0,0,.04); }
.inv-header { display: flex; justify-content: space-between; gap: 2rem; }
.org { font-size: .9rem; color: #3b4652; }
.org-name { font-size: 1.15rem; font-weight: 700; color: var(--ink); margin-bottom: .2rem; }
.org-logo img { max-height: 90px; max-width: 220px; }
.logo-placeholder { display: grid; place-items: center; width: 160px; height: 80px; border: 2px dashed var(--line); border-radius: var(--radius); color: var(--muted); }
.doc-title { font-size: 1.6rem; letter-spacing: .08em; color: var(--green-d); margin: 1.5rem 0 1.25rem; font-weight: 300; }
.inv-grid { display: grid; grid-template-columns: 1fr 260px; gap: 2rem; margin-bottom: 1.25rem; }
.contact-card { margin-top: .75rem; padding: .75rem 1rem; background: var(--bg); border-radius: var(--radius); font-size: .9rem; }
.contact-card .lbl { font-size: .75rem; text-transform: uppercase; color: var(--muted); letter-spacing: .04em; }

table.lines { width: 100%; border-collapse: collapse; margin-top: .5rem; }
table.lines th { text-align: left; font-size: .75rem; text-transform: uppercase; color: var(--muted); padding: .5rem .4rem; border-bottom: 2px solid var(--line); }
table.lines td { padding: .3rem .4rem; border-bottom: 1px solid var(--line); }
table.lines td input, table.lines td select { margin: 0; }
table.lines .drag { width: 22px; cursor: grab; color: #a8b0ba; text-align: center; user-select: none; }
table.lines .n { width: 28px; color: var(--muted); }
table.lines th.num, table.lines td.num { width: 130px; }
table.lines tr.dragging { opacity: .4; }
table.lines tr.drop-target td { border-top: 2px solid var(--green); }
.line-actions { display: flex; gap: .5rem; margin: .75rem 0; }

.totals { margin-left: auto; width: 340px; margin-bottom: 1.5rem; }
.t-row { display: flex; justify-content: space-between; align-items: center; padding: .35rem 0; }
.t-total { font-size: 1.15rem; font-weight: 700; border-top: 2px solid var(--ink); margin-top: .3rem; padding-top: .6rem; }
.totals .link { margin-top: .3rem; }

.block { border-top: 1px solid var(--line); padding-top: .5rem; margin-top: 1rem; }
.block-head { display: flex; align-items: center; justify-content: space-between; }
.pay-badges { display: flex; flex-wrap: wrap; gap: .4rem; margin-bottom: .75rem; }
.badge { border: 1px solid var(--line); padding: .2rem .6rem; border-radius: 4px; font-size: .8rem; background: #fafbfc; font-weight: 600; }
.pay-edit { background: var(--bg); padding: .75rem 1rem; border-radius: var(--radius); margin-bottom: .75rem; }
.two-col { display: grid; grid-template-columns: 1fr 1fr; gap: 1.5rem; margin-top: 1rem; }
.dropzone { border: 2px dashed var(--line); border-radius: var(--radius); padding: 1rem; text-align: center; }
.dropzone.over { border-color: var(--green); background: var(--green-l); }
.file-list { list-style: none; padding: 0; margin: .5rem 0; }
.file-list li { padding: .35rem 0; border-bottom: 1px solid var(--line); display: flex; gap: .75rem; align-items: center; }

/* Settings panel */
.editor-side h3 { border-top: 1px solid var(--line); padding-top: 1rem; }
.inline-field { display: flex; align-items: center; flex-wrap: wrap; font-weight: 400; margin-bottom: .75rem; }
.inline-field input { margin-top: 0; }
.row { display: flex; gap: .75rem; }
.row > label { flex: 1; }
.summary { background: var(--green-l); color: var(--green-d); border-left: 4px solid var(--green); padding: .75rem 1rem; border-radius: 4px; font-weight: 600; margin-bottom: 1rem; }
.weekdays { display: flex; flex-wrap: wrap; gap: .3rem; align-items: center; margin-bottom: .75rem; }
.weekdays .lbl { margin-right: .3rem; font-weight: 500; }
.day { margin: 0; }
.day input { display: none; }
.day span { display: inline-block; padding: .35rem .5rem; border: 1px solid #b8c0ca; border-radius: 4px; cursor: pointer; font-size: .8rem; font-weight: 600; }
.day input:checked + span { background: var(--green); border-color: var(--green); color: #fff; }
.switch { display: flex; align-items: center; gap: .6rem; font-weight: 400; cursor: pointer; }
.switch input { display: none; }
.slider { width: 38px; height: 22px; background: #b8c0ca; border-radius: 999px; position: relative; flex: none; transition: background .15s; }
.slider::after { content: ""; position: absolute; top: 3px; left: 3px; width: 16px; height: 16px; background: #fff; border-radius: 50%; transition: transform .15s; }
.switch input:checked + .slider { background: var(--green); }
.switch input:checked + .slider::after { transform: translateX(16px); }

@media (max-width: 1000px) {
  body.editor-page { overflow: auto; }
  .editor { display: block; height: auto; }
  .editor-side { border-left: 0; border-top: 1px solid var(--line); }
  .editor-foot { position: sticky; bottom: 0; height: var(--foot); }
  .inv-grid, .two-col, .grid-2, .grid-4, .grid-5 { grid-template-columns: 1fr; }
  .span-2 { grid-column: auto; }
  .totals { width: 100%; }
  .topbar { gap: 1rem; overflow-x: auto; }
}
