/* ============================================
   easyNDIS Invoice App — Styles
   ============================================ */

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

/* ---------- CSS Variables (Light Mode) ---------- */
:root {
  --bg: #ffffff;
  --bg2: #f5f5f4;
  --bg3: #efefed;
  --bg-info: #e6f1fb;
  --bg-success: #eaf3de;
  --bg-danger: #fcebeb;
  --bg-warning: #faeeda;
  --text: #1a1a1a;
  --text2: #6b6b6b;
  --text3: #9f9f9f;
  --text-info: #185fa5;
  --text-success: #3b6d11;
  --text-danger: #a32d2d;
  --text-warning: #854f0b;
  --border: rgba(0, 0, 0, 0.12);
  --border2: rgba(0, 0, 0, 0.22);
  --radius: 8px;
  --radius-lg: 12px;
  --teal: #0f6e56;
  --teal-bg: #e1f5ee;
  --teal-text: #085041;
}

/* ---------- Dark Mode ---------- */
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #1e1e1c;
    --bg2: #2a2a28;
    --bg3: #323230;
    --bg-info: rgba(12, 68, 124, 0.13);
    --bg-success: rgba(39, 80, 10, 0.13);
    --bg-danger: rgba(121, 31, 31, 0.13);
    --bg-warning: rgba(99, 56, 6, 0.13);
    --teal-bg: rgba(4, 52, 44, 0.27);
    --text: #f0f0ee;
    --text2: #a0a09e;
    --text3: #6a6a68;
    --text-info: #85b7eb;
    --text-success: #97c459;
    --text-danger: #f09595;
    --text-warning: #ef9f27;
    --teal: #5dcaa5;
    --teal-text: #9fe1cb;
    --border: rgba(255, 255, 255, 0.1);
    --border2: rgba(255, 255, 255, 0.2);
  }
}

/* ---------- Base ---------- */
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg3);
  color: var(--text);
  font-size: 15px;
  line-height: 1.5;
  min-height: 100vh;
}

/* ---------- Utility ---------- */
.hidden { display: none !important; }

/* ---------- Auth Screen ---------- */
.auth-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 2rem 1rem;
  background: var(--bg3);
}

.auth-card {
  width: 100%;
  max-width: 400px;
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 2rem;
}

.auth-logo {
  font-size: 20px;
  font-weight: 500;
  color: var(--teal);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 8px;
  margin-bottom: 1.5rem;
}

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

.auth-panel h2 {
  font-size: 18px;
  font-weight: 500;
  margin-bottom: 4px;
}

.auth-sub {
  font-size: 14px;
  color: var(--text2);
  margin-bottom: 1.25rem;
}

.auth-field { margin-bottom: 12px; }

.auth-submit {
  width: 100%;
  justify-content: center;
  margin-top: 4px;
}

.auth-links {
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 4px;
  margin-top: 1rem;
}

.link-btn {
  background: none;
  border: none;
  color: var(--text-info);
  font-size: 13px;
  padding: 4px 8px;
  cursor: pointer;
}

.link-btn:hover { text-decoration: underline; }

.auth-error {
  background: var(--bg-danger);
  color: var(--text-danger);
  font-size: 13px;
  padding: 8px 12px;
  border-radius: var(--radius);
  margin-bottom: 12px;
}

.auth-success {
  background: var(--bg-success);
  color: var(--text-success);
  font-size: 13px;
  padding: 8px 12px;
  border-radius: var(--radius);
  margin-bottom: 12px;
}

/* ---------- Top Navigation ---------- */
.topbar {
  background: var(--bg);
  border-bottom: 0.5px solid var(--border);
  padding: 0 1.5rem;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  height: 54px;
  position: sticky;
  top: 0;
  z-index: 10;
}

.logo {
  font-size: 16px;
  font-weight: 500;
  color: var(--teal);
  margin-right: 1rem;
  display: flex;
  align-items: center;
  gap: 8px;
}

.logo span {
  color: var(--text2);
  font-weight: 400;
  font-size: 13px;
}

.tab {
  padding: 0 12px;
  height: 54px;
  display: flex;
  align-items: center;
  font-size: 14px;
  color: var(--text2);
  border: none;
  background: none;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  gap: 6px;
  white-space: nowrap;
}

.tab.active {
  color: var(--text);
  border-bottom-color: var(--teal);
  font-weight: 500;
}

.tab i { font-size: 16px; }

.topbar-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.user-display {
  font-size: 13px;
  color: var(--text2);
  max-width: 160px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.sign-out-btn {
  font-size: 13px;
  padding: 6px 10px;
}

/* ---------- Layout ---------- */
.main {
  max-width: 820px;
  margin: 2rem auto;
  padding: 0 1rem;
}

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

.page-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 1rem;
}

.page-header h2 {
  font-size: 18px;
  font-weight: 500;
}

/* ---------- Cards ---------- */
.card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 1.25rem;
  margin-bottom: 1rem;
}

.card-title {
  font-size: 12px;
  font-weight: 500;
  color: var(--text2);
  text-transform: uppercase;
  letter-spacing: 0.05em;
  margin-bottom: 12px;
  display: flex;
  align-items: center;
  gap: 6px;
}

.card-title i {
  font-size: 15px;
  color: var(--teal);
}

/* ---------- Form Fields ---------- */
.field-label {
  font-size: 12px;
  color: var(--text2);
  margin-bottom: 4px;
}

.field-required::after {
  content: ' *';
  color: var(--text-danger);
}

input[type=text],
input[type=email],
input[type=tel],
input[type=number],
input[type=date],
select,
textarea {
  width: 100%;
  background: var(--bg);
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  padding: 8px 10px;
  font-size: 14px;
  color: var(--text);
  font-family: inherit;
  outline: none;
  transition: border-color 0.15s;
}

input:focus,
select:focus,
textarea:focus {
  border-color: var(--teal);
  box-shadow: 0 0 0 3px rgba(15, 110, 86, 0.1);
}

textarea { resize: none; }

select {
  appearance: none;
  background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' viewBox='0 0 24 24' fill='none' stroke='%236b6b6b' stroke-width='2'%3E%3Cpath d='M6 9l6 6 6-6'/%3E%3C/svg%3E");
  background-repeat: no-repeat;
  background-position: right 10px center;
  padding-right: 28px;
}

/* ---------- Grids ---------- */
.grid2 { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.grid3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; margin-bottom: 12px; }
.grid4 { display: grid; grid-template-columns: 1fr 1fr 1fr 1fr; gap: 12px; margin-bottom: 12px; }

/* ---------- Buttons ---------- */
button {
  display: inline-flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  font-size: 14px;
  font-family: inherit;
  border: 0.5px solid var(--border2);
  border-radius: var(--radius);
  background: var(--bg);
  color: var(--text);
  cursor: pointer;
  transition: background 0.12s;
}

button:hover { background: var(--bg2); }
button:active { transform: scale(0.98); }
button i { font-size: 16px; }

button.primary {
  background: var(--teal);
  color: #fff;
  border-color: var(--teal);
}

button.primary:hover { opacity: 0.88; }

.btn-row {
  display: flex;
  gap: 8px;
  flex-wrap: wrap;
  margin-top: 1rem;
}

.add-line {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text-info);
  font-size: 13px;
  padding: 6px 6px 0;
  display: inline-flex;
  align-items: center;
  gap: 4px;
}

/* ---------- Invoice List ---------- */
.inv-row {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius);
  padding: 10px 14px;
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 6px;
  transition: background 0.1s;
}

.inv-row:hover { background: var(--bg2); }
.inv-num { font-size: 13px; font-weight: 500; min-width: 90px; }
.inv-participant { font-size: 13px; color: var(--text2); flex: 1; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.inv-total { font-size: 13px; font-weight: 500; min-width: 80px; text-align: right; }
.inv-date { font-size: 12px; color: var(--text3); min-width: 84px; text-align: right; }

/* ---------- Badges ---------- */
.badge {
  font-size: 11px;
  padding: 2px 8px;
  border-radius: var(--radius);
  white-space: nowrap;
}

.badge.sent { background: var(--bg-success); color: var(--text-success); }
.badge.draft { background: var(--bg2); color: var(--text2); }
.badge.paid { background: var(--teal-bg); color: var(--teal-text); }

/* ---------- Icon Buttons ---------- */
.icon-btn {
  background: none;
  border: none;
  padding: 4px 6px;
  cursor: pointer;
  color: var(--text3);
  font-size: 16px;
  border-radius: var(--radius);
}

.icon-btn:hover { background: var(--bg2); color: var(--text); }
.icon-btn.danger:hover { color: var(--text-danger); background: var(--bg-danger); }

/* ---------- Support Items Table ---------- */
.items-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
  table-layout: fixed;
  margin-bottom: 6px;
}

.items-table th {
  font-size: 11px;
  font-weight: 500;
  color: var(--text2);
  text-align: left;
  padding: 6px 6px;
  border-bottom: 0.5px solid var(--border);
  background: var(--bg2);
}

.items-table th.r { text-align: right; }
.col-cat { width: 130px; }
.col-hrs { width: 56px; }
.col-rate { width: 80px; }
.col-amt { width: 88px; }
.col-del { width: 32px; }

.irow td {
  padding: 4px 6px;
  vertical-align: top;
  border-bottom: 0.5px solid var(--border);
}

.irow td input,
.irow td select { width: 100%; font-size: 13px; }
.irow td.r input { text-align: right; }

.amt-disp {
  display: block;
  text-align: right;
  padding: 8px 0;
  font-size: 13px;
}

.item-dates {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 4px;
  margin-top: 4px;
}

.item-dates .dl,
.support-num .dl {
  font-size: 10px;
  color: var(--text3);
  margin-bottom: 2px;
}

.item-dates input { font-size: 12px; }
.support-num { margin-top: 4px; }

.del-btn {
  background: none;
  border: none;
  cursor: pointer;
  color: var(--text3);
  font-size: 17px;
  padding: 6px 2px;
  display: flex;
  align-items: center;
}

.del-btn:hover { color: var(--text-danger); }

/* ---------- Totals ---------- */
.totals-box {
  width: 280px;
  margin-left: auto;
  margin-top: 1.5rem;
  font-size: 14px;
}

.trow {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  color: var(--text2);
  border-bottom: 0.5px solid var(--border);
  align-items: center;
}

.trow.grand {
  font-weight: 500;
  font-size: 16px;
  color: var(--text);
  border-bottom: none;
  padding-top: 10px;
}

.trow input { width: 54px; text-align: right; }

/* ---------- Participant Cards ---------- */
.client-card {
  background: var(--bg);
  border: 0.5px solid var(--border);
  border-radius: var(--radius-lg);
  padding: 12px 14px;
  display: flex;
  align-items: center;
  gap: 12px;
  margin-bottom: 8px;
}

.avatar {
  width: 40px;
  height: 40px;
  border-radius: 50%;
  background: var(--teal-bg);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 13px;
  font-weight: 500;
  color: var(--teal-text);
  flex-shrink: 0;
}

.client-name { font-size: 14px; font-weight: 500; }
.client-meta { font-size: 12px; color: var(--text2); margin-top: 2px; }
.ndis-num { font-size: 12px; color: var(--teal); font-weight: 500; margin-top: 2px; }

/* ---------- Empty States ---------- */
.empty {
  text-align: center;
  padding: 3rem 1rem;
  color: var(--text3);
  font-size: 14px;
}

.empty i {
  font-size: 32px;
  display: block;
  margin-bottom: 8px;
}

/* ---------- Responsive ---------- */
@media (max-width: 600px) {
  .grid2, .grid3, .grid4 { grid-template-columns: 1fr; }
  .col-cat { width: 100px; }
  .col-hrs { width: 50px; }
  .col-rate { width: 70px; }
  .col-amt { width: 72px; }
  .topbar { padding: 0 1rem; }
  .tab span { display: none; }
}

/* ---------- Print ---------- */
@media print {
  .topbar,
  .btn-row,
  .add-line,
  .del-btn,
  .no-print { display: none !important; }

  body { background: white; }
  .main { max-width: 100%; margin: 0; padding: 1rem; }
  .card { border: 0.5px solid #ddd; page-break-inside: avoid; }
  .panel { display: block !important; }
  #tab-invoices, #tab-clients { display: none !important; }
  #tab-editor { display: block !important; }
  .items-table th { background: #f5f5f5 !important; -webkit-print-color-adjust: exact; }
}
