:root {
  --green: #064f3b;
  --green-2: #0b6a4f;
  --ink: #17211d;
  --muted: #64736d;
  --line: #dce5e1;
  --soft: #f5f8f6;
  --white: #ffffff;
  --danger: #a83232;
  --shadow: 0 12px 30px rgba(16, 35, 28, 0.08);
}

* { box-sizing: border-box; }
body {
  margin: 0;
  font-family: Arial, Helvetica, sans-serif;
  color: var(--ink);
  background: var(--soft);
  -webkit-text-size-adjust: 100%;
}

button, input, select { font: inherit; }
button { cursor: pointer; }
button, .file-import, input, select { min-height: 44px; }

.app-shell {
  min-height: 100vh;
  display: grid;
  grid-template-columns: 280px 1fr;
}

.sidebar {
  background: var(--green);
  color: var(--white);
  padding: 24px 18px;
  display: flex;
  flex-direction: column;
  gap: 30px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 12px;
}

.brand-mark {
  width: 48px;
  height: 48px;
  border: 2px solid rgba(255,255,255,.65);
  display: grid;
  place-items: center;
  font-weight: 800;
}

.brand strong, .brand span { display: block; }
.brand span { font-size: 13px; opacity: .78; margin-top: 3px; }

nav { display: grid; gap: 8px; }
.nav-btn {
  border: 0;
  background: transparent;
  color: var(--white);
  text-align: left;
  padding: 12px 14px;
  border-radius: 8px;
}
.nav-btn:hover, .nav-btn.active { background: rgba(255,255,255,.14); }

.workspace {
  padding: max(26px, env(safe-area-inset-top)) max(26px, env(safe-area-inset-right)) max(26px, env(safe-area-inset-bottom)) max(26px, env(safe-area-inset-left));
  min-width: 0;
}

.topbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 16px;
  margin-bottom: 24px;
}

h1, h2, p { margin-top: 0; }
h1 { font-size: 28px; margin-bottom: 6px; }
h2 { font-size: 18px; margin-bottom: 16px; }
.topbar p, .muted { color: var(--muted); margin-bottom: 0; }
.top-actions, .action-grid { display: flex; gap: 10px; flex-wrap: wrap; }

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

.stats-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat, .panel {
  background: var(--white);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: var(--shadow);
}

.stat { padding: 18px; }
.stat span { color: var(--muted); font-size: 13px; }
.stat strong { display: block; margin-top: 10px; font-size: 30px; }

.panel {
  padding: 20px;
  margin-bottom: 18px;
}

.panel-head {
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 14px;
  margin-bottom: 12px;
}
.panel-head h2 { margin-bottom: 0; }

.invoice-layout {
  display: grid;
  grid-template-columns: repeat(2, minmax(280px, 1fr));
  gap: 18px;
}
.actions-panel { grid-column: 1 / -1; display: flex; gap: 10px; flex-wrap: wrap; }
.wide-panel { grid-column: 1 / -1; }

.form-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 14px;
}

.filter-grid {
  display: grid;
  grid-template-columns: repeat(5, minmax(140px, 1fr));
  gap: 12px;
  margin-bottom: 14px;
}

.license-upload {
  display: flex;
  flex-wrap: wrap;
  gap: 12px;
  align-items: center;
  margin-bottom: 14px;
}

.license-grid input {
  border-color: #cbdad4;
}

.license-grid input.auto-filled {
  background: #f0faf6;
  border-color: var(--green-2);
}

label {
  display: grid;
  gap: 7px;
  color: var(--muted);
  font-size: 13px;
  font-weight: 700;
}

input, select {
  width: 100%;
  border: 1px solid var(--line);
  background: var(--white);
  color: var(--ink);
  border-radius: 8px;
  padding: 11px 12px;
  min-height: 42px;
  pointer-events: auto;
}
input:focus, select:focus {
  outline: 3px solid rgba(11,106,79,.18);
  border-color: var(--green-2);
}
input[readonly] { background: #eef3f1; }
.search { max-width: 420px; }
.status-pill {
  display: inline-block;
  min-width: 70px;
  text-align: center;
  border-radius: 999px;
  padding: 5px 9px;
  font-size: 12px;
  font-weight: 800;
}
.status-paid { background: #dff4ea; color: #07553e; }
.status-unpaid { background: #fff1d9; color: #8a5400; }

.choice-grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(180px, 1fr));
  gap: 12px;
}
.choice-grid.compact { grid-template-columns: repeat(3, minmax(120px, 1fr)); }

.choice {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  display: grid;
  grid-template-columns: auto 1fr;
  gap: 10px;
  align-items: start;
}
.choice input { width: auto; min-height: 0; margin-top: 3px; }
.choice strong { display: block; margin-bottom: 7px; }
.choice ul { margin: 0; padding-left: 18px; color: var(--muted); font-size: 13px; line-height: 1.5; }

.primary, .secondary, .danger, .file-import {
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 14px;
  font-weight: 700;
  touch-action: manipulation;
}
.primary { background: var(--green); color: var(--white); }
.secondary { background: var(--white); color: var(--green); border-color: var(--line); }
.danger { background: var(--danger); color: var(--white); }
.file-import {
  background: var(--white);
  color: var(--green);
  border-color: var(--line);
  display: inline-grid;
  place-items: center;
}
.file-import input { display: none; }

.table-wrap { overflow: auto; border: 1px solid var(--line); border-radius: 8px; }
table { width: 100%; border-collapse: collapse; min-width: 1180px; }
th, td { text-align: left; padding: 12px; border-bottom: 1px solid var(--line); vertical-align: top; }
th { background: #eef5f2; color: var(--green); font-size: 13px; }
td { font-size: 14px; }
tr:last-child td { border-bottom: 0; }
.empty { text-align: center; color: var(--muted); padding: 30px; }
.row-actions { display: flex; gap: 8px; flex-wrap: wrap; }
.row-actions button { min-height: 34px; padding: 7px 10px; }

.settings-grid {
  display: grid;
  grid-template-columns: minmax(220px, 1fr) repeat(4, auto);
  gap: 12px;
  align-items: end;
  margin-top: 18px;
}

dialog {
  border: 0;
  border-radius: 8px;
  box-shadow: 0 24px 80px rgba(0,0,0,.24);
}
dialog::backdrop { background: rgba(10, 24, 19, .55); }
.lock-dialog { width: min(420px, calc(100vw - 28px)); }
.lock-dialog form { display: grid; gap: 14px; padding: 8px; }
.lock-dialog small { color: var(--danger); min-height: 18px; }

.pdf-dialog {
  width: min(980px, calc(100vw - 28px));
  max-height: 92vh;
  overflow: auto;
}
.dialog-head {
  position: sticky;
  top: 0;
  background: var(--white);
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 12px;
  padding-bottom: 14px;
  margin-bottom: 14px;
  border-bottom: 1px solid var(--line);
}
.dialog-head h2 { margin: 0; }

.invoice-paper {
  width: 794px;
  min-height: 1123px;
  margin: 0 auto;
  background: var(--white);
  color: #17211d;
  padding: 46px;
  border: 1px solid var(--line);
}
.pdf-header {
  display: flex;
  justify-content: space-between;
  border-bottom: 4px solid var(--green);
  padding-bottom: 22px;
  margin-bottom: 24px;
}
.pdf-brand h2 { color: var(--green); font-size: 28px; margin-bottom: 4px; }
.pdf-brand p, .pdf-meta p { margin: 4px 0; color: #596963; }
.pdf-title { text-align: right; }
.pdf-title strong { display: block; color: var(--green); font-size: 30px; margin-bottom: 10px; }
.pdf-section { margin: 18px 0; }
.pdf-section h3 {
  background: var(--green);
  color: var(--white);
  padding: 9px 12px;
  margin: 0 0 10px;
  font-size: 14px;
}
.pdf-two { display: grid; grid-template-columns: 1fr 1fr; gap: 18px; }
.pdf-table { width: 100%; min-width: 0; border: 1px solid #d7e2de; }
.pdf-table th, .pdf-table td { padding: 10px; }
.total-box {
  margin-left: auto;
  width: 300px;
  background: #eef5f2;
  border: 1px solid #d7e2de;
  padding: 16px;
  text-align: right;
}
.total-box span { color: #596963; }
.total-box strong { display: block; color: var(--green); font-size: 28px; margin-top: 6px; }
.pdf-footer {
  margin-top: 34px;
  border-top: 1px solid #d7e2de;
  padding-top: 12px;
  color: #596963;
  font-size: 12px;
  text-align: center;
}

@media (max-width: 980px) {
  .app-shell { grid-template-columns: 1fr; }
  .sidebar { position: static; }
  nav { grid-template-columns: repeat(3, 1fr); }
  .nav-btn { text-align: center; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
  .invoice-layout, .form-grid { grid-template-columns: 1fr; }
  .filter-grid { grid-template-columns: repeat(2, 1fr); }
  .settings-grid { grid-template-columns: 1fr; }
}

@media (max-width: 640px) {
  .sidebar { padding: 16px; gap: 16px; }
  .brand-mark { width: 42px; height: 42px; }
  .workspace { padding: 16px; }
  h1 { font-size: 24px; }
  .topbar, .panel-head { align-items: stretch; flex-direction: column; }
  nav { grid-template-columns: 1fr; }
  .nav-btn { text-align: left; }
  .top-actions, .action-grid, .actions-panel { display: grid; grid-template-columns: 1fr; }
  .license-upload { display: grid; grid-template-columns: 1fr; }
  .choice-grid, .choice-grid.compact { grid-template-columns: 1fr; }
  .filter-grid { grid-template-columns: 1fr; }
  .stats-grid { grid-template-columns: 1fr; }
  .panel { padding: 16px; }
  .invoice-paper { width: 100%; min-height: auto; padding: 18px; font-size: 13px; }
  .pdf-header { flex-direction: column; gap: 14px; }
  .pdf-title { text-align: left; }
  .pdf-two { grid-template-columns: 1fr; }
  .total-box { width: 100%; }
}

@media (max-width: 430px) {
  .workspace { padding-left: 12px; padding-right: 12px; }
  .panel { padding: 14px; }
  th, td { padding: 10px; }
}
