/* invoice.css — Invoice module. Uses the tokens from theme.css (--surface, --accent, …). */

body { margin: 0; }
body .main.invoice-page { padding: 30px 36px 56px; min-height: 100vh; box-sizing: border-box; }

/* ---------- Header ---------- */
.inv-head { display: flex; align-items: flex-end; justify-content: space-between; gap: 18px; flex-wrap: wrap; margin-bottom: 22px; }
.inv-head h1 { margin: 0 0 6px; font-size: 26px !important; font-weight: 700; letter-spacing: -0.025em; }
.inv-sub { margin: 0; color: var(--muted); font-size: 14px; max-width: 62ch; }
.inv-head-tools { display: flex; align-items: center; gap: 10px; }
.draft-state[hidden] { display: none; }
.draft-state { font-size: 12.5px; color: var(--faint); display: inline-flex; align-items: center; gap: 6px; }
.draft-state .material-icons { font-size: 15px; }
.ghost-btn { height: 34px; padding: 0 12px; display: inline-flex; align-items: center; gap: 6px; border-radius: 9px; border: 1px solid var(--border-strong); background: transparent; color: var(--text-2); font: 600 13px var(--font); cursor: pointer; }
.ghost-btn:hover { color: #fff; border-color: #3a4254; background: var(--raised); }
.ghost-btn .material-icons { font-size: 17px; }

/* ---------- Layout ---------- */
.inv-grid { display: grid; grid-template-columns: minmax(0, 1fr) 360px; gap: 22px; align-items: start; }

/* ---------- Form sections ---------- */
.inv-form { display: flex; flex-direction: column; gap: 14px; }
.inv-section { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 18px 20px 20px; }
.inv-section-head { display: flex; align-items: center; gap: 10px; margin: 0 0 16px; }
.inv-section-head .material-icons { font-size: 18px; width: 30px; height: 30px; display: grid; place-items: center; border-radius: 8px; color: var(--accent-text); background: var(--accent-soft); }
.inv-section-head h2 { margin: 0; font-size: 15px !important; font-weight: 600; }
.inv-section-head .sec-count { margin-left: auto; font-size: 12px; color: var(--faint); font-variant-numeric: tabular-nums; }
.inv-section-head .sec-count.done { color: var(--success); }

.inv-fields { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px 16px; }
.inv-field { display: flex; flex-direction: column; gap: 6px; min-width: 0; }
.inv-field.full { grid-column: 1 / -1; }
.inv-field .inv-label { font-size: 13px; font-weight: 500; color: var(--text-2); }
.inv-field .inv-label .req { color: var(--accent-text); margin-left: 2px; }
.inv-field :is(input, select, textarea) {
  width: 100%; box-sizing: border-box;
  height: 40px; padding: 0 12px;
  border-radius: 9px; border: 1px solid var(--border-strong);
  background: var(--raised); color: #fff;
  font: 400 14px var(--font);
  transition: border-color .15s, box-shadow .15s, background-color .15s;
}
.inv-field textarea { height: auto; min-height: 96px; padding: 10px 12px; line-height: 1.5; resize: vertical; }
.inv-field select { appearance: none; -webkit-appearance: none; padding-right: 36px; cursor: pointer;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='8' viewBox='0 0 12 8'%3E%3Cpath d='M1 1.5l5 5 5-5' fill='none' stroke='%238b93a4' stroke-width='1.6' stroke-linecap='round' stroke-linejoin='round'/%3E%3C/svg%3E");
  background-repeat: no-repeat; background-position: right 13px center; }
.inv-field select:invalid, .inv-field select.empty { color: var(--faint); }
.inv-field select option { color: #fff; background: var(--raised); }
.inv-field :is(input, select, textarea):hover { border-color: #3a4254; }
.inv-field :is(input, select, textarea):focus { border-color: var(--accent); box-shadow: 0 0 0 3px var(--accent-ring); background: var(--raised-2); }
.inv-field.invalid :is(input, select, textarea) { border-color: rgba(242,109,120,.7); }
.inv-field.invalid :is(input, select, textarea):focus { box-shadow: 0 0 0 3px rgba(242,109,120,.25); }
.inv-field .err { display: none; font-size: 12.5px; color: var(--danger); }
.inv-field.invalid .err { display: block; }

.inv-form-foot { display: none; }

/* "Send invoice to" choice */
.choice { display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 10px; }
.choice-opt { position: relative; cursor: pointer; min-width: 0; }
.choice-opt input { position: absolute; opacity: 0; pointer-events: none; }
.choice-body { display: flex; align-items: flex-start; gap: 10px; height: 100%; box-sizing: border-box; padding: 12px; border-radius: 10px; border: 1px solid var(--border-strong); background: var(--raised); transition: border-color .15s, background-color .15s, box-shadow .15s; }
.choice-body .material-icons { font-size: 20px; color: var(--muted); margin-top: 1px; }
.choice-text { display: flex; flex-direction: column; gap: 3px; min-width: 0; }
.choice-text b { font-size: 13.5px; font-weight: 600; color: #e6e8ee; }
.choice-text small { font-size: 12px; color: var(--faint); overflow-wrap: anywhere; line-height: 1.4; }
.choice-text small.warn { color: var(--warning); }
.choice-opt:hover .choice-body { border-color: #3a4254; }
.choice-opt input:checked + .choice-body { border-color: var(--accent); background: var(--accent-soft); }
.choice-opt input:checked + .choice-body .material-icons { color: var(--accent-text); }
.choice-opt input:focus-visible + .choice-body { box-shadow: 0 0 0 3px var(--accent-ring); }

/* ---------- Live preview (the slip) ---------- */
.inv-aside { position: sticky; top: 20px; display: flex; flex-direction: column; gap: 12px; }
.slip { position: relative; background: var(--surface); border: 1px solid var(--border); border-radius: 14px; overflow: hidden; }
.slip-top { position: relative; padding: 18px 20px 16px; background: linear-gradient(180deg, rgba(91,120,246,.10), transparent); border-bottom: 1px dashed var(--border-strong); }
.slip-kicker { font-size: 12.5px; color: var(--muted); display: flex; justify-content: space-between; gap: 10px; }
.slip-no { margin-top: 6px; font-size: 24px; font-weight: 700; letter-spacing: -0.02em; color: #f6f7fb; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; }
.slip-oc { margin-top: 2px; font-size: 13px; color: var(--text-2); font-variant-numeric: tabular-nums; }
/* punched notches where the dashed line meets the edges */
.slip-top::before, .slip-top::after { content: ""; position: absolute; width: 14px; height: 14px; border-radius: 50%; background: var(--bg); border: 1px solid var(--border); }
.slip-top::before { left: -8px; bottom: -8px; }
.slip-top::after { right: -8px; bottom: -8px; }

.slip-body { padding: 16px 20px 6px; }
.slip-block { padding-bottom: 14px; }
.slip-block + .slip-block { padding-top: 14px; border-top: 1px solid var(--border); }
.slip-label { font-size: 12px; color: var(--faint); margin-bottom: 6px; }
.slip-strong { font-size: 14.5px; font-weight: 600; color: #f3f4f7; overflow-wrap: anywhere; }
.slip-line { white-space: pre-line; font-size: 13px; color: var(--text-2); line-height: 1.5; overflow-wrap: anywhere; }
.slip-empty { color: var(--faint); font-style: italic; }
.slip-rows { display: flex; flex-direction: column; gap: 7px; }
.slip-row { display: flex; justify-content: space-between; gap: 12px; font-size: 13px; }
.slip-row span:first-child { color: var(--muted); flex: none; }
.slip-row span:last-child { color: #e6e8ee; text-align: right; overflow-wrap: anywhere; min-width: 0; }
.slip-row.muted span:last-child { color: var(--faint); }
.slip-total { display: flex; align-items: baseline; justify-content: space-between; gap: 12px; margin: 0 20px; padding: 14px 0 18px; border-top: 1px dashed var(--border-strong); }
.slip-total span { font-size: 13px; color: var(--muted); }
.slip-total b { font-size: 22px; font-weight: 700; color: #fff; letter-spacing: -0.02em; font-variant-numeric: tabular-nums; overflow-wrap: anywhere; text-align: right; }

/* Progress + submit */
.submit-card { background: var(--surface); border: 1px solid var(--border); border-radius: 14px; padding: 16px; }
.progress-text { display: flex; justify-content: space-between; font-size: 13px; color: var(--text-2); margin-bottom: 8px; }
.progress-text b { font-weight: 600; color: #fff; font-variant-numeric: tabular-nums; }
.progress { height: 6px; border-radius: 99px; background: var(--raised-2); overflow: hidden; }
.progress i { display: block; height: 100%; width: 0; border-radius: inherit; background: var(--accent); transition: width .3s cubic-bezier(.2,.75,.2,1), background-color .2s; }
.progress.complete i { background: var(--success); }
.missing { margin: 10px 0 0; font-size: 12.5px; color: var(--faint); line-height: 1.5; }
.missing button { padding: 0; border: 0; background: none; color: var(--accent-text); font: inherit; cursor: pointer; text-decoration: underline; text-decoration-color: rgba(157,176,255,.4); text-underline-offset: 2px; }
.missing button:hover { color: #fff; }

.send-to { display: flex; gap: 8px; margin: 12px 0 0; padding: 10px 12px; border-radius: 9px; background: var(--raised); font-size: 12.5px; color: var(--muted); line-height: 1.45; }
.send-to .material-icons { font-size: 16px; color: var(--accent-text); margin-top: 1px; }
.send-to b { color: #e6e8ee; font-weight: 600; overflow-wrap: anywhere; }
.send-to b.none { color: var(--warning); }
.ghost-btn.wide { width: 100%; justify-content: center; height: 38px; margin-top: 10px; }

.primary-btn { width: 100%; height: 42px; margin-top: 14px; display: inline-flex; align-items: center; justify-content: center; gap: 8px; border-radius: 10px; border: 1px solid transparent; background: var(--accent); color: #fff; font: 600 14px var(--font); cursor: pointer; }
.primary-btn:hover { background: var(--accent-hover); }
.primary-btn[disabled] { opacity: .75; cursor: progress; }
.primary-btn .material-icons { font-size: 18px; }
.send-note { margin: 10px 0 0; font-size: 12.5px; color: var(--faint); min-height: 1em; }
.send-note:empty { display: none; }

.spin { animation: spin .8s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ---------- Email preview dialog ---------- */
.email-dialog { width: min(820px, calc(100vw - 32px)); max-height: calc(100vh - 48px); padding: 0; border: 1px solid var(--border-strong); border-radius: 14px; background: var(--surface); color: var(--text); box-shadow: 0 30px 80px rgba(0,0,0,.55); overflow: hidden; }
.email-dialog[open] { display: flex; flex-direction: column; }
.email-dialog::backdrop { background: rgba(5,6,9,.65); backdrop-filter: blur(4px); -webkit-backdrop-filter: blur(4px); }
.em-head { display: flex; align-items: center; justify-content: space-between; padding: 14px 16px 10px 20px; }
.em-head h2 { margin: 0; font-size: 16px !important; font-weight: 600; }
.icon-btn { width: 34px; height: 34px; display: grid; place-items: center; border-radius: 8px; border: 1px solid transparent; background: transparent; color: var(--muted); cursor: pointer; }
.icon-btn:hover { background: var(--raised); color: #fff; }
.em-meta { margin: 0; padding: 0 20px 12px; display: grid; gap: 6px; border-bottom: 1px solid var(--border); }
.em-meta div { display: grid; grid-template-columns: 64px minmax(0, 1fr); gap: 10px; font-size: 13px; }
.em-meta dt { color: var(--faint); }
.em-meta dd { margin: 0; color: #e6e8ee; overflow-wrap: anywhere; }
.em-meta dd.none { color: var(--warning); }
.em-note { display: flex; gap: 8px; align-items: flex-start; margin: 0; padding: 10px 20px; font-size: 12.5px; color: var(--warning); background: rgba(245,165,36,.08); border-bottom: 1px solid var(--border); }
.em-note[hidden] { display: none; }
.em-note .material-icons { font-size: 16px; }
.em-body { flex: 1; min-height: 0; overflow: auto; background: #fff; }
.em-body iframe { display: block; width: 100%; height: 900px; border: 0; background: #fff; }
.em-foot { display: flex; justify-content: flex-end; gap: 10px; padding: 12px 16px; border-top: 1px solid var(--border); }
.em-foot .primary-btn { width: auto; margin: 0; padding: 0 18px; height: 38px; }
.em-foot .ghost-btn { height: 38px; }

/* ---------- Toast ---------- */
.inv-toast { position: fixed; right: 24px; bottom: 24px; z-index: 300; display: flex; align-items: flex-start; gap: 10px; max-width: 380px; padding: 12px 14px; border-radius: 12px; background: var(--raised); border: 1px solid var(--border-strong); box-shadow: 0 20px 50px rgba(0,0,0,.5); color: #e6e8ee; font-size: 13.5px; line-height: 1.45;
  opacity: 0; transform: translateY(8px); pointer-events: none; transition: opacity .2s, transform .2s; }
.inv-toast.show { opacity: 1; transform: none; pointer-events: auto; }
.inv-toast .material-icons { font-size: 20px; flex: none; }
.inv-toast.ok .material-icons { color: var(--success); }
.inv-toast.bad .material-icons { color: var(--danger); }
.inv-toast b { display: block; color: #fff; font-weight: 600; }

@media (prefers-reduced-motion: reduce) { .spin { animation: none; } .progress i, .inv-toast { transition: none; } }

/* ---------- Responsive ---------- */
@media (max-width: 1200px) {
  .inv-grid { grid-template-columns: minmax(0, 1fr) 320px; }
}
@media (max-width: 1050px) {
  body .main.invoice-page { padding: 22px 18px 40px; }
  .inv-grid { grid-template-columns: 1fr; }
  .inv-aside { position: static; }
  .inv-aside .submit-card { display: none; }
  .inv-form-foot { display: block; }
}
@media (max-width: 640px) {
  .inv-fields { grid-template-columns: 1fr; }
  .choice { grid-template-columns: 1fr; }
  .inv-section { padding: 16px; }
  .inv-toast { left: 16px; right: 16px; bottom: 16px; max-width: none; }
}
