/* Skillvard NIOS Bill Generator */

:root {
  --lime: #a2cf02;
  --lime-dark: #7fa000;
  --lime-soft: #f3f9d9;
  --ink: #111111;
  --muted: #5c5c5c;
  --line: #e6e6e6;
  --paper: #ffffff;
  --bg: #f4f5f0;
  --danger: #c0392b;
  --radius: 12px;
  --shadow: 0 12px 40px rgba(17, 17, 17, 0.08);
}

* { box-sizing: border-box; margin: 0; padding: 0; }

body {
  font-family: "DM Sans", system-ui, sans-serif;
  background:
    radial-gradient(ellipse 80% 50% at 10% -10%, rgba(162, 207, 2, 0.18), transparent 55%),
    radial-gradient(ellipse 60% 40% at 100% 0%, rgba(162, 207, 2, 0.08), transparent 50%),
    var(--bg);
  color: var(--ink);
  min-height: 100vh;
  line-height: 1.45;
}

.hidden { display: none !important; }

.app { max-width: 1320px; margin: 0 auto; padding: 24px 20px 48px; }

.topbar {
  display: flex; align-items: flex-start; justify-content: space-between;
  gap: 16px; margin-bottom: 20px; flex-wrap: wrap;
}
.topbar h1 { font-size: 1.4rem; font-weight: 700; letter-spacing: -0.02em; }
.topbar p { color: var(--muted); font-size: 0.9rem; margin-top: 2px; }
.mode-badge {
  display: inline-block; margin-top: 6px; padding: 3px 10px; border-radius: 999px;
  font-size: 0.72rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em;
  background: var(--lime-soft); color: var(--lime-dark);
}

.actions { display: flex; gap: 8px; flex-wrap: wrap; }

button, .btn {
  font-family: inherit; font-weight: 600; font-size: 0.88rem; border: none;
  border-radius: 999px; padding: 9px 16px; cursor: pointer;
  transition: transform 0.15s ease, background 0.15s ease;
}
button:hover { transform: translateY(-1px); }
button:disabled { opacity: 0.5; cursor: not-allowed; transform: none; }

.btn-primary { background: var(--lime); color: var(--ink); box-shadow: 0 4px 14px rgba(162, 207, 2, 0.35); }
.btn-secondary { background: var(--ink); color: #fff; }
.btn-ghost { background: transparent; color: var(--ink); border: 1.5px solid var(--line); }
.btn-danger { background: #fde8e8; color: var(--danger); }
.btn-sm { padding: 6px 12px; font-size: 0.8rem; }

.stats-grid {
  display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; margin-bottom: 20px;
}
@media (max-width: 900px) { .stats-grid { grid-template-columns: repeat(2, 1fr); } }
.stat-card {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 14px 16px; box-shadow: var(--shadow);
}
.stat-card .label { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em; color: var(--muted); }
.stat-card .value { font-size: 1.25rem; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }
.stat-card .value.green { color: var(--lime-dark); }
.stat-card .value.red { color: var(--danger); }

.tabs {
  display: flex; gap: 6px; margin-bottom: 20px; flex-wrap: wrap;
}
.tab {
  padding: 8px 16px; border-radius: 999px; background: var(--paper);
  border: 1.5px solid var(--line); font-weight: 600; font-size: 0.88rem; cursor: pointer;
}
.tab.active { background: var(--ink); color: #fff; border-color: var(--ink); }

.tab-panel { display: none; }
.tab-panel.active { display: block; }

.layout {
  display: grid; grid-template-columns: minmax(300px, 400px) 1fr;
  gap: 24px; align-items: start;
}
@media (max-width: 960px) { .layout { grid-template-columns: 1fr; } }

.panel {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  padding: 20px; box-shadow: var(--shadow);
}
.panel h2 {
  font-size: 0.78rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); margin-bottom: 14px; padding-bottom: 8px; border-bottom: 1px solid var(--line);
}
.form-section + .form-section { margin-top: 20px; }

label { display: block; font-size: 0.78rem; font-weight: 600; color: var(--muted); margin-bottom: 5px; }
input, select, textarea {
  width: 100%; font-family: inherit; font-size: 0.92rem; padding: 9px 11px;
  border: 1.5px solid var(--line); border-radius: 8px; background: #fafafa; color: var(--ink); outline: none;
}
input:focus, select:focus, textarea:focus { border-color: var(--lime); background: #fff; }
input[readonly] { background: #f0f0f0; color: var(--muted); cursor: default; }
.field { margin-bottom: 12px; }
.row-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 10px; }
.auto-hint { font-size: 0.75rem; color: var(--muted); margin-top: -6px; margin-bottom: 10px; }

.template-chips { display: flex; flex-wrap: wrap; gap: 6px; margin-bottom: 10px; }
.chip {
  padding: 6px 12px; border-radius: 999px; background: var(--lime-soft);
  border: 1px solid var(--lime); color: var(--lime-dark); font-size: 0.8rem; font-weight: 600; cursor: pointer;
}

.items-editor { display: flex; flex-direction: column; gap: 8px; }
.item-row {
  display: grid; grid-template-columns: 1fr 70px 88px 32px; gap: 6px; align-items: center;
}
.item-row button {
  width: 32px; height: 32px; padding: 0; border-radius: 8px;
  background: #f5f5f5; color: var(--danger); font-size: 1.1rem;
}
.add-item {
  margin-top: 8px; width: 100%; border-radius: 8px;
  background: var(--lime-soft); color: var(--lime-dark); border: 1.5px dashed var(--lime);
}

/* Bill */
.bill-wrap { background: transparent; padding: 0; box-shadow: none; border: none; }
.bill {
  background: var(--paper); border: 1px solid var(--line); border-radius: var(--radius);
  box-shadow: var(--shadow); padding: 40px 44px; position: relative; overflow: hidden;
}
.bill::before { content: ""; position: absolute; top: 0; left: 0; right: 0; height: 4px; background: var(--lime); }
.bill-header { display: flex; justify-content: space-between; align-items: flex-start; gap: 24px; padding-bottom: 24px; border-bottom: 2px solid var(--ink); }
.logo { height: 56px; width: auto; display: block; }
.bill-meta { text-align: right; }
.bill-meta .doc-type { font-size: 1.55rem; font-weight: 700; letter-spacing: -0.03em; line-height: 1.1; }
.bill-meta .doc-type span { color: var(--lime-dark); }
.meta-line { font-size: 0.88rem; color: var(--muted); margin-top: 6px; font-variant-numeric: tabular-nums; }
.meta-line strong { color: var(--ink); font-family: "JetBrains Mono", monospace; font-weight: 500; font-size: 0.84rem; }
.biz-block { margin-top: 18px; font-size: 0.86rem; color: var(--muted); line-height: 1.55; }
.biz-block a { color: var(--ink); text-decoration: none; font-weight: 600; }
.parties { display: grid; grid-template-columns: 1fr 1fr; gap: 28px; margin: 28px 0 8px; }
.party-label { font-size: 0.7rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.1em; color: var(--lime-dark); margin-bottom: 8px; }
.party-name { font-size: 1.05rem; font-weight: 700; margin-bottom: 4px; }
.party-detail { font-size: 0.88rem; color: var(--muted); }
.status-pill { display: inline-block; margin-top: 10px; padding: 4px 12px; border-radius: 999px; font-size: 0.75rem; font-weight: 700; text-transform: uppercase; letter-spacing: 0.06em; }
.status-paid { background: var(--lime-soft); color: var(--lime-dark); }
.status-pending { background: #fff3cd; color: #8a6d00; }
.status-partial { background: #e8f0fe; color: #1a56a8; }

table.items { width: 100%; border-collapse: collapse; margin-top: 28px; font-size: 0.92rem; }
table.items thead th {
  text-align: left; font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.08em;
  color: var(--muted); padding: 10px 12px; border-bottom: 2px solid var(--ink); background: var(--lime-soft);
}
table.items thead th:nth-child(2), table.items thead th:nth-child(3), table.items thead th:nth-child(4),
table.items tbody td:nth-child(2), table.items tbody td:nth-child(3), table.items tbody td:nth-child(4) { text-align: right; }
table.items tbody td { padding: 14px 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
table.items tbody tr:last-child td { border-bottom: 1px solid var(--ink); }

.totals { margin-top: 20px; display: flex; justify-content: flex-end; }
.totals-box { width: min(280px, 100%); }
.totals-row { display: flex; justify-content: space-between; padding: 6px 0; font-size: 0.9rem; color: var(--muted); }
.totals-row.grand { margin-top: 8px; padding-top: 12px; border-top: 2px solid var(--ink); font-size: 1.15rem; font-weight: 700; color: var(--ink); }
.totals-row.grand .amount, .totals-row.paid-row .amount { color: var(--lime-dark); font-family: "JetBrains Mono", monospace; }
.totals-row.paid-row { color: var(--ink); font-weight: 600; }
.totals-row.balance-row { margin-top: 4px; padding-top: 10px; border-top: 1px dashed var(--line); font-weight: 600; color: var(--ink); }
.totals-row.balance-row .amount { font-family: "JetBrains Mono", monospace; }
.totals-row.balance-row.due .amount { color: var(--danger); }
.totals-row.balance-row.clear .amount { color: var(--lime-dark); }

.notes { margin-top: 32px; padding: 16px 18px; background: #fafafa; border-left: 3px solid var(--lime); border-radius: 0 8px 8px 0; font-size: 0.86rem; color: var(--muted); }
.notes strong { color: var(--ink); }
.bill-footer { margin-top: 36px; padding-top: 18px; border-top: 1px solid var(--line); display: flex; justify-content: space-between; gap: 16px; flex-wrap: wrap; font-size: 0.8rem; color: var(--muted); }
.thanks { font-weight: 600; color: var(--ink); font-size: 0.92rem; }

/* History & tables */
.toolbar { display: flex; gap: 8px; margin-bottom: 14px; flex-wrap: wrap; }
.data-table { width: 100%; border-collapse: collapse; font-size: 0.88rem; }
.data-table th, .data-table td { padding: 10px 12px; border-bottom: 1px solid var(--line); text-align: left; }
.data-table th { font-size: 0.72rem; text-transform: uppercase; letter-spacing: 0.06em; color: var(--muted); background: #fafafa; }
.data-table tr:hover td { background: #fafafa; }
.table-actions { display: flex; gap: 6px; flex-wrap: wrap; }

.student-list, .logs-list { display: flex; flex-direction: column; gap: 8px; max-height: 420px; overflow-y: auto; }
.student-card, .log-item {
  padding: 12px 14px; border: 1px solid var(--line); border-radius: 8px; background: #fafafa;
}
.student-card { cursor: pointer; transition: border-color 0.15s; }
.student-card:hover { border-color: var(--lime); }
.student-card strong, .log-item strong { display: block; color: var(--ink); margin-bottom: 2px; }
.student-card span, .log-item span { color: var(--muted); font-size: 0.82rem; }
.log-empty { color: var(--muted); font-size: 0.85rem; font-style: italic; padding: 12px 0; }

.template-editor { display: flex; flex-direction: column; gap: 8px; }
.template-row {
  display: grid; grid-template-columns: 1fr 100px 32px; gap: 6px; align-items: center;
}

/* Login overlay */
.overlay {
  position: fixed; inset: 0; background: rgba(17,17,17,0.55);
  display: flex; align-items: center; justify-content: center; z-index: 2000; padding: 20px;
}
.login-box {
  background: var(--paper); border-radius: var(--radius); padding: 28px; width: min(360px, 100%);
  box-shadow: var(--shadow); text-align: center;
}
.login-box h2 { margin-bottom: 6px; }
.login-box p { color: var(--muted); font-size: 0.9rem; margin-bottom: 18px; }
.login-box input { margin-bottom: 14px; text-align: center; font-size: 1.2rem; letter-spacing: 0.2em; }

.toast {
  position: fixed; bottom: 24px; right: 24px; padding: 12px 18px; border-radius: 10px;
  font-size: 0.9rem; font-weight: 600; box-shadow: var(--shadow); z-index: 3000;
  opacity: 0; transform: translateY(8px); transition: opacity 0.2s, transform 0.2s; pointer-events: none;
}
.toast.show { opacity: 1; transform: translateY(0); }
.toast.success { background: var(--lime); color: var(--ink); }
.toast.error { background: #fde8e8; color: var(--danger); }

@media print {
  @page { size: A4; margin: 12mm; }
  body { background: #fff; }
  .no-print, .overlay { display: none !important; }
  .app { padding: 0; max-width: none; }
  .tab-panel { display: block !important; }
  #panel-create .layout { display: block; }
  .bill { box-shadow: none; border: none; border-radius: 0; padding: 0; }
  .bill::before { display: none; }
}
