:root {
  color-scheme: light;
  --bg: #f4f6f8;
  --panel: #ffffff;
  --ink: #17202a;
  --muted: #677381;
  --line: #dce2e8;
  --accent: #0d6efd;
  --accent-dark: #084db4;
  --good: #15803d;
  --warn: #b45309;
  --bad: #b91c1c;
  --soft: #eef4ff;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  min-height: 100vh;
  background: var(--bg);
  color: var(--ink);
}

.login-screen {
  display: grid;
  min-height: 100vh;
  place-items: center;
  padding: 24px;
}

.login-screen.hidden,
.auth-locked {
  display: none;
}

.login-card {
  width: min(420px, 100%);
  padding: 24px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--panel);
  box-shadow: 0 18px 50px rgba(17, 24, 39, 0.12);
}

.login-brand {
  margin-bottom: 22px;
  color: var(--ink);
}

.login-brand small {
  color: var(--muted);
}

.login-message {
  min-height: 20px;
  color: var(--bad);
  font-weight: 700;
}

button,
input,
select,
textarea {
  font: inherit;
}

.app-shell {
  display: grid;
  grid-template-columns: 250px minmax(0, 1fr);
  min-height: 100vh;
}

.sidebar {
  background: #111827;
  color: #fff;
  padding: 24px 18px;
}

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

.brand-mark {
  display: grid;
  width: 44px;
  height: 44px;
  place-items: center;
  border-radius: 8px;
  background: var(--accent);
  font-weight: 800;
}

.brand small {
  display: block;
  margin-top: 2px;
  color: #b9c3cf;
}

.nav {
  display: grid;
  gap: 8px;
}

.nav-item {
  border: 0;
  border-radius: 8px;
  padding: 12px 14px;
  background: transparent;
  color: #d8dee7;
  text-align: left;
  cursor: pointer;
}

.nav-item:hover,
.nav-item.active {
  background: #243044;
  color: #fff;
}

.main {
  padding: 26px;
  min-width: 0;
}

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

.eyebrow {
  margin: 0 0 4px;
  color: var(--muted);
  font-weight: 700;
  text-transform: uppercase;
  font-size: 0.75rem;
  letter-spacing: 0.08em;
}

h1,
h2,
p {
  margin-top: 0;
}

h1 {
  margin-bottom: 0;
  font-size: clamp(1.8rem, 3vw, 2.5rem);
}

h2 {
  margin-bottom: 16px;
  font-size: 1.1rem;
}

.topbar-actions {
  display: flex;
  gap: 10px;
  align-items: center;
}

input,
select,
textarea {
  width: 100%;
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 10px 11px;
  background: #fff;
  color: var(--ink);
}

textarea {
  min-height: 92px;
  resize: vertical;
}

#globalSearch {
  width: min(320px, 42vw);
}

.hidden-file {
  display: none;
}

.primary-button,
.ghost-button,
.segment,
.icon-button {
  border: 0;
  border-radius: 8px;
  cursor: pointer;
}

.primary-button {
  background: var(--accent);
  color: #fff;
  padding: 10px 15px;
  font-weight: 750;
}

.primary-button:hover {
  background: var(--accent-dark);
}

.ghost-button {
  background: var(--soft);
  color: var(--accent-dark);
  padding: 8px 12px;
  font-weight: 700;
}

.view {
  display: none;
}

.active-view {
  display: block;
}

.stat-grid {
  display: grid;
  grid-template-columns: repeat(3, minmax(150px, 1fr));
  gap: 14px;
  margin-bottom: 18px;
}

.stat-card,
.panel,
.form-panel,
.table-panel,
.job-card {
  background: var(--panel);
  border: 1px solid var(--line);
  border-radius: 8px;
  box-shadow: 0 12px 34px rgba(17, 24, 39, 0.05);
}

.stat-card {
  padding: 18px;
}

.stat-card span {
  color: var(--muted);
  font-weight: 700;
}

.stat-card strong {
  display: block;
  margin-top: 8px;
  font-size: 2rem;
}

.dashboard-grid {
  display: grid;
  grid-template-columns: 1.5fr 1fr;
  gap: 18px;
}

.panel {
  padding: 18px;
}

.panel-header,
.section-toolbar,
.job-card-header,
.row-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
}

.panel-header h2 {
  margin: 0;
}

.list {
  display: grid;
  gap: 10px;
}

.list-item {
  display: flex;
  justify-content: space-between;
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid var(--line);
  padding: 10px 0;
}

.list-item:last-child {
  border-bottom: 0;
}

.muted {
  color: var(--muted);
}

.badge {
  display: inline-flex;
  align-items: center;
  border-radius: 999px;
  padding: 5px 10px;
  font-size: 0.82rem;
  font-weight: 750;
  background: #edf2f7;
  color: #334155;
  white-space: nowrap;
}

.badge.good {
  background: #dcfce7;
  color: var(--good);
}

.badge.warn {
  background: #fef3c7;
  color: var(--warn);
}

.badge.bad {
  background: #fee2e2;
  color: var(--bad);
}

.section-toolbar {
  margin-bottom: 16px;
}

#calendar .section-toolbar {
  justify-content: flex-start;
}

#calendarMonth {
  margin: 0;
  min-width: 190px;
  text-align: center;
}

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

.segment {
  background: #fff;
  border: 1px solid var(--line);
  color: var(--muted);
  padding: 9px 12px;
}

.segment.active {
  background: #111827;
  color: #fff;
  border-color: #111827;
}

.card-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
  gap: 14px;
}

.calendar-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(120px, 1fr));
  gap: 1px;
  overflow: hidden;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: var(--line);
}

.calendar-day-name,
.calendar-day {
  background: #fff;
}

.calendar-day-name {
  padding: 10px;
  color: var(--muted);
  font-size: 0.78rem;
  font-weight: 800;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

.calendar-day {
  min-height: 132px;
  padding: 9px;
}

.calendar-day.today {
  box-shadow: inset 0 0 0 2px var(--accent);
}

.calendar-date {
  margin-bottom: 8px;
  font-weight: 800;
}

.muted-day {
  background: #f8fafc;
}

.calendar-jobs {
  display: grid;
  gap: 6px;
}

.calendar-job {
  display: grid;
  gap: 2px;
  width: 100%;
  border: 1px solid #cfe0ff;
  border-radius: 8px;
  padding: 7px;
  background: var(--soft);
  color: var(--accent-dark);
  text-align: left;
  cursor: pointer;
}

.calendar-job span {
  color: #526174;
  font-size: 0.78rem;
}

.job-card {
  padding: 16px;
}

.job-card h3 {
  margin: 0 0 5px;
}

.job-meta {
  display: grid;
  gap: 8px;
  margin: 14px 0;
  color: var(--muted);
}

.job-note,
.invoice-note {
  color: var(--bad);
  font-weight: 800;
}

.two-column {
  display: grid;
  grid-template-columns: minmax(260px, 360px) 1fr;
  gap: 18px;
  align-items: start;
}

.form-panel,
.table-panel {
  padding: 18px;
}

.full {
  width: 100%;
}

label {
  display: grid;
  gap: 6px;
  margin-bottom: 12px;
  color: var(--muted);
  font-weight: 700;
}

.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
}

.check-row input {
  width: auto;
}

table {
  width: 100%;
  border-collapse: collapse;
}

th,
td {
  padding: 12px 10px;
  border-bottom: 1px solid var(--line);
  text-align: left;
  vertical-align: middle;
}

th {
  color: var(--muted);
  font-size: 0.82rem;
  text-transform: uppercase;
  letter-spacing: 0.05em;
}

tr:last-child td {
  border-bottom: 0;
}

.small-button {
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  padding: 7px 10px;
  cursor: pointer;
}

.danger-button {
  border-color: #fecaca;
  color: var(--bad);
  font-weight: 800;
}

dialog {
  width: min(560px, calc(100vw - 28px));
  border: 0;
  border-radius: 8px;
  padding: 0;
  box-shadow: 0 28px 80px rgba(15, 23, 42, 0.3);
}

dialog::backdrop {
  background: rgba(17, 24, 39, 0.48);
}

#invoiceDialog {
  width: min(900px, calc(100vw - 28px));
}

.dialog-form {
  padding: 22px;
}

.mode-switch {
  display: flex;
  flex-wrap: wrap;
  gap: 10px;
  margin-bottom: 14px;
}

.mode-switch label {
  display: flex;
  align-items: center;
  gap: 8px;
  margin: 0;
  padding: 9px 12px;
  border: 1px solid var(--line);
  border-radius: 8px;
  background: #fff;
  color: var(--ink);
}

.mode-switch input {
  width: auto;
}

.field-group {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  margin: 0 0 14px;
}

.field-group legend {
  padding: 0 8px;
  color: var(--muted);
  font-weight: 800;
}

.field-group h3 {
  margin: 6px 0 12px;
  font-size: 0.95rem;
}

.quote-row {
  display: grid;
  grid-template-columns: minmax(180px, 1fr) 100px 130px auto;
  gap: 10px;
  align-items: end;
  margin-bottom: 10px;
}

.quote-row:nth-of-type(2) {
  grid-template-columns: minmax(180px, 1fr) 90px 130px auto;
}

.quote-items {
  display: grid;
  gap: 8px;
  margin-top: 12px;
}

.quote-line {
  display: grid;
  grid-template-columns: 1fr auto auto;
  gap: 10px;
  align-items: center;
  padding: 9px 0;
  border-top: 1px solid var(--line);
}

.quote-total {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: 12px;
  margin-top: 12px;
  text-align: right;
  font-weight: 800;
}

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

.lookup-row {
  display: grid;
  grid-template-columns: minmax(0, 1fr) auto;
  gap: 10px;
  align-items: end;
}

.hidden {
  display: none;
}

.dialog-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin-bottom: 14px;
}

.dialog-header h2 {
  margin: 0;
}

.icon-button {
  width: 34px;
  height: 34px;
  background: #edf2f7;
  color: var(--ink);
}

.invoice-dialog {
  padding: 22px;
}

.invoice-document {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 24px;
  background: #fff;
}

.invoice-title {
  display: flex;
  justify-content: space-between;
  gap: 18px;
  border-bottom: 2px solid #111827;
  padding-bottom: 16px;
  margin-bottom: 18px;
}

.invoice-title h3 {
  margin: 0 0 6px;
  font-size: 1.6rem;
}

.invoice-meta,
.invoice-parties {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 18px;
  margin-bottom: 18px;
}

.invoice-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
  margin-top: 16px;
}

.profit-grid {
  display: grid;
  grid-template-columns: repeat(4, minmax(130px, 1fr));
  gap: 12px;
  margin-bottom: 16px;
}

.profit-box {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 14px;
  background: #f8fafc;
}

.profit-box span {
  display: block;
  color: var(--muted);
  font-weight: 750;
  margin-bottom: 6px;
}

.profit-box strong {
  font-size: 1.25rem;
}

.empty {
  color: var(--muted);
  padding: 18px;
  text-align: center;
  border: 1px dashed var(--line);
  border-radius: 8px;
}

@media (max-width: 920px) {
  .app-shell {
    grid-template-columns: 1fr;
  }

  .sidebar {
    position: sticky;
    top: 0;
    z-index: 5;
    padding: 14px;
  }

  .brand {
    margin-bottom: 12px;
  }

  .nav {
    grid-auto-flow: column;
    overflow-x: auto;
    padding-bottom: 3px;
  }

  .nav-item {
    white-space: nowrap;
  }

  .topbar,
  .topbar-actions,
  .dashboard-grid,
  .form-grid,
  .invoice-meta,
  .invoice-parties,
  .profit-grid,
  .quote-row,
  .quote-row:nth-of-type(2),
  .two-column {
    display: grid;
    grid-template-columns: 1fr;
  }

  #globalSearch {
    width: 100%;
  }

  .stat-grid {
    grid-template-columns: repeat(2, minmax(0, 1fr));
  }

  .calendar-grid {
    grid-template-columns: repeat(7, minmax(150px, 1fr));
    overflow-x: auto;
  }
}

@media (max-width: 560px) {
  .main {
    padding: 18px 14px;
  }

  .stat-grid {
    grid-template-columns: 1fr;
  }

  th:nth-child(3),
  td:nth-child(3) {
    display: none;
  }
}

@media print {
  body.printing-invoice {
    background: #fff;
  }

  body.printing-invoice .app-shell,
  body.printing-invoice .no-print,
  body.printing-invoice dialog::backdrop {
    display: none;
  }

  body.printing-invoice #invoiceDialog {
    display: block;
    position: static;
    width: 100%;
    max-width: none;
    box-shadow: none;
    border: 0;
  }

  body.printing-invoice .invoice-dialog,
  body.printing-invoice .invoice-document {
    padding: 0;
    border: 0;
    box-shadow: none;
  }
}
