:root {
  --bg: #f6f3ee;
  --surface: #ffffff;
  --surface-2: #fbf9f5;
  --border: #e6e0d6;
  --text: #241f19;
  --text-muted: #7a7267;
  --wood: #8a5a34;
  --wood-dark: #6b4526;
  --wood-light: #c98f52;
  --accent: #c8792f;
  --accent-soft: #f3e2cc;
  --success: #2f8a4f;
  --success-soft: #e3f3e8;
  --danger: #c0392b;
  --danger-soft: #fbe6e3;
  --sidebar-bg: #241a12;
  --sidebar-text: #efe6da;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(36, 31, 25, 0.06), 0 8px 24px rgba(36, 31, 25, 0.06);
}

* {
  box-sizing: border-box;
}

html,
body {
  min-height: 100%;
}

body {
  margin: 0;
  font-family: 'Segoe UI', -apple-system, BlinkMacSystemFont, 'Inter', Roboto, sans-serif;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

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

/* ------------------------------- App Shell ------------------------------- */

.app-shell {
  display: flex;
  height: 100vh;
  overflow: hidden;
}

.sidebar {
  width: 248px;
  flex-shrink: 0;
  background: var(--sidebar-bg);
  color: var(--sidebar-text);
  display: flex;
  flex-direction: column;
  padding: 20px 14px;
}

.brand {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 6px 8px 22px;
}

.brand-mark {
  width: 38px;
  height: 38px;
  border-radius: 9px;
  background: linear-gradient(140deg, var(--wood-light), var(--wood-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12px;
  letter-spacing: 0.5px;
  color: #fff;
}

.brand-name {
  font-weight: 700;
  font-size: 15px;
  color: #fff;
}

.brand-tag {
  font-size: 11.5px;
  color: #b8ab98;
}

.nav {
  display: flex;
  flex-direction: column;
  gap: 3px;
  flex: 1;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 11px;
  padding: 10px 12px;
  border-radius: 8px;
  color: #cfc2b0;
  text-decoration: none;
  font-size: 14px;
  font-weight: 500;
  transition: background 0.12s ease, color 0.12s ease;
}

.nav-item svg {
  opacity: 0.85;
  flex-shrink: 0;
}

.nav-item:hover {
  background: rgba(255, 255, 255, 0.06);
  color: #fff;
}

.nav-item.active {
  background: var(--accent);
  color: #fff;
}

.sidebar-footer {
  display: flex;
  flex-direction: column;
  gap: 10px;
  padding-top: 14px;
  border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.user-row {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 4px;
}

.avatar {
  width: 32px;
  height: 32px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--wood-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 13px;
  flex-shrink: 0;
}

.user-name {
  font-size: 13px;
  font-weight: 600;
  color: #fff;
}

.user-phone {
  font-size: 11.5px;
  color: #b8ab98;
}

.content {
  flex: 1;
  overflow-y: auto;
  padding: 28px 36px 60px;
}

/* ------------------------------- Breadcrumbs ------------------------------- */

.breadcrumbs {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.breadcrumb-item {
  color: var(--text-muted);
  text-decoration: none;
  font-weight: 600;
  transition: color 0.12s ease;
}

a.breadcrumb-item:hover {
  color: var(--accent);
  text-decoration: underline;
}

.breadcrumb-item.current {
  color: var(--text);
  font-weight: 700;
}

.breadcrumb-sep {
  color: var(--border);
}

/* --------------------------------- Layout --------------------------------- */

.page-header {
  display: flex;
  align-items: flex-start;
  justify-content: space-between;
  gap: 16px;
  margin-bottom: 22px;
}

.page-title {
  font-size: 22px;
  font-weight: 700;
  margin: 0 0 4px;
}

.page-subtitle {
  color: var(--text-muted);
  font-size: 13.5px;
  margin: 0;
}

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 22px;
}

.grid {
  display: grid;
  gap: 18px;
}

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

.grid-3 {
  grid-template-columns: repeat(3, 1fr);
}

.grid-4 {
  grid-template-columns: repeat(4, 1fr);
}

/* -------------------------------- Buttons -------------------------------- */

.btn {
  appearance: none;
  border: 1px solid transparent;
  border-radius: 8px;
  padding: 10px 16px;
  font-size: 13.5px;
  font-weight: 600;
  cursor: pointer;
  transition: filter 0.1s ease, background 0.1s ease;
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
}

.btn:disabled {
  opacity: 0.55;
  cursor: not-allowed;
}

.btn-primary {
  background: var(--accent);
  color: #fff;
}

.btn-primary:hover:not(:disabled) {
  filter: brightness(1.06);
}

.btn-secondary {
  background: var(--surface-2);
  color: var(--text);
  border-color: var(--border);
}

.btn-secondary:hover:not(:disabled) {
  background: var(--accent-soft);
}

.btn-ghost {
  background: transparent;
  color: #cfc2b0;
  border-color: rgba(255, 255, 255, 0.14);
}

.btn-ghost:hover {
  background: rgba(255, 255, 255, 0.08);
  color: #fff;
}

.btn-danger {
  background: var(--danger-soft);
  color: var(--danger);
}

.btn-danger:hover {
  filter: brightness(0.97);
}

.btn-sm {
  padding: 6px 11px;
  font-size: 12.5px;
}

.btn-block {
  width: 100%;
}

.btn-icon {
  padding: 8px;
}

/* --------------------------------- Forms --------------------------------- */

.field {
  display: flex;
  flex-direction: column;
  gap: 6px;
  margin-bottom: 14px;
}

.field label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.field input,
.field select,
.field textarea {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text);
  outline: none;
  transition: border-color 0.1s ease;
}

.field input:focus,
.field select:focus,
.field textarea:focus {
  border-color: var(--accent);
}

.field .hint {
  font-size: 11.5px;
  color: var(--text-muted);
}

.field-inline {
  display: flex;
  align-items: center;
  gap: 8px;
}

/* --------------------------------- Table --------------------------------- */

.table-wrap {
  overflow-x: auto;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface);
}

table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13.5px;
}

thead th {
  text-align: left;
  padding: 12px 14px;
  background: var(--surface-2);
  color: var(--text-muted);
  font-weight: 600;
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.03em;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody td {
  padding: 11px 14px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

tbody tr:last-child td {
  border-bottom: none;
}

tbody tr:hover {
  background: var(--surface-2);
}

.text-right {
  text-align: right;
}

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

.empty-state {
  padding: 40px 20px;
  text-align: center;
  color: var(--text-muted);
}

/* --------------------------------- Badges --------------------------------- */

.badge {
  display: inline-flex;
  align-items: center;
  gap: 5px;
  padding: 3px 9px;
  border-radius: 999px;
  font-size: 11.5px;
  font-weight: 600;
}

.badge-success {
  background: var(--success-soft);
  color: var(--success);
}

.badge-pending {
  background: var(--accent-soft);
  color: var(--wood-dark);
}

/* -------------------------------- Stat cards ------------------------------- */

.stat-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 18px 20px;
  box-shadow: var(--shadow);
}

.stat-label {
  font-size: 12.5px;
  color: var(--text-muted);
  font-weight: 600;
  margin-bottom: 6px;
}

.stat-value {
  font-size: 26px;
  font-weight: 700;
}

.stat-icon {
  width: 40px;
  height: 40px;
  border-radius: 10px;
  background: var(--accent-soft);
  color: var(--wood-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  margin-bottom: 12px;
}

/* --------------------------------- Login --------------------------------- */

.login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  background: radial-gradient(circle at top left, #3a2a1c, var(--sidebar-bg) 55%);
  padding: 20px;
}

.login-card {
  width: 100%;
  max-width: 380px;
  background: var(--surface);
  border-radius: 16px;
  padding: 34px 32px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.35);
}

.login-logo {
  width: 52px;
  height: 52px;
  border-radius: 13px;
  background: linear-gradient(140deg, var(--wood-light), var(--wood-dark));
  display: flex;
  align-items: center;
  justify-content: center;
  color: #fff;
  font-weight: 700;
  margin-bottom: 16px;
}

.login-title {
  font-size: 20px;
  font-weight: 700;
  margin: 0 0 4px;
}

.login-subtitle {
  color: var(--text-muted);
  font-size: 13.5px;
  margin: 0 0 26px;
}

.login-error {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 13px;
  margin-bottom: 16px;
}

.login-hint {
  margin-top: 18px;
  font-size: 12px;
  color: var(--text-muted);
  background: var(--surface-2);
  border-radius: 8px;
  padding: 10px 12px;
  border: 1px dashed var(--border);
}

/* --------------------------------- Misc --------------------------------- */

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 18px;
  flex-wrap: wrap;
}

.spacer {
  flex: 1;
}

.section-title {
  font-size: 15px;
  font-weight: 700;
  margin: 0 0 14px;
}

.divider {
  height: 1px;
  background: var(--border);
  margin: 20px 0;
}

.pill-input {
  border: 1px solid var(--border);
  border-radius: 999px;
  padding: 8px 14px;
  font-size: 13px;
  min-width: 220px;
}

.date-filter {
  display: flex;
  align-items: center;
  gap: 8px;
}

.date-filter-label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.date-filter input[type='date'] {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 7px 10px;
  font-size: 13px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.date-filter input[type='date']:focus {
  border-color: var(--accent);
}

.calc-summary {
  background: var(--surface-2);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 16px 18px;
}

.calc-row {
  display: flex;
  justify-content: space-between;
  padding: 6px 0;
  font-size: 13.5px;
}

.calc-row.total {
  border-top: 1px solid var(--border);
  margin-top: 6px;
  padding-top: 12px;
  font-weight: 700;
  font-size: 16px;
}

.modal-backdrop {
  position: fixed;
  inset: 0;
  background: rgba(20, 16, 12, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 40;
  padding: 20px;
}

.modal {
  background: var(--surface);
  border-radius: 14px;
  width: 100%;
  max-width: 480px;
  padding: 24px;
  box-shadow: 0 30px 60px rgba(0, 0, 0, 0.3);
}

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

.link-btn {
  background: none;
  border: none;
  color: var(--accent);
  cursor: pointer;
  font-size: 13px;
  font-weight: 600;
  padding: 0;
}

.unit-toggle {
  display: inline-flex;
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow: hidden;
}

.unit-toggle button {
  border: none;
  background: var(--surface);
  color: var(--text-muted);
  padding: 7px 14px;
  font-size: 12.5px;
  font-weight: 600;
  cursor: pointer;
}

.unit-toggle button.active {
  background: var(--accent);
  color: #fff;
}

/* ------------------------------ Product Picker ----------------------------- */

.product-picker {
  position: relative;
  min-width: 200px;
}

.product-picker input {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 8px 10px;
  font-size: 13.5px;
  background: var(--surface);
  color: var(--text);
  outline: none;
}

.product-picker input:focus {
  border-color: var(--accent);
}

.product-picker-list {
  position: absolute;
  top: calc(100% + 4px);
  left: 0;
  right: 0;
  z-index: 30;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 8px;
  box-shadow: var(--shadow);
  max-height: 220px;
  overflow-y: auto;
  padding: 4px;
}

.product-picker-option {
  padding: 8px 10px;
  border-radius: 6px;
  cursor: pointer;
  font-size: 13.5px;
}

.product-picker-option:hover,
.product-picker-option.highlighted {
  background: var(--accent-soft);
}

.product-picker-empty {
  padding: 10px;
  font-size: 13px;
  color: var(--text-muted);
}

/* -------------------------------- Line Items -------------------------------- */

.line-items {
  display: flex;
  flex-direction: column;
  gap: 14px;
}

.line-item-card {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 16px 18px;
}

.line-item-head {
  display: flex;
  align-items: flex-end;
  gap: 14px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}

.line-item-number {
  width: 26px;
  height: 26px;
  border-radius: 50%;
  background: var(--accent-soft);
  color: var(--wood-dark);
  display: flex;
  align-items: center;
  justify-content: center;
  font-weight: 700;
  font-size: 12.5px;
  flex-shrink: 0;
  margin-bottom: 2px;
}

.line-item-product {
  flex: 1;
  min-width: 220px;
  display: flex;
  flex-direction: column;
  gap: 6px;
  position: relative;
}

.line-item-product label {
  font-size: 12.5px;
  font-weight: 600;
  color: var(--text-muted);
}

.line-item-size-tag {
  align-self: flex-start;
  font-size: 11.5px;
  font-weight: 600;
  color: var(--wood-dark);
  background: var(--accent-soft);
  border-radius: 999px;
  padding: 3px 10px;
}

.line-item-remove {
  margin-left: auto;
}

.line-item-dims-row,
.line-item-calc-row {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(96px, 1fr));
  gap: 12px;
  margin-bottom: 12px;
}

.line-item-dims-row .field,
.line-item-calc-row .field {
  margin-bottom: 0;
}

.field-readout .readout-value {
  border: 1px solid var(--border);
  border-radius: 8px;
  padding: 10px 12px;
  font-size: 14px;
  background: var(--surface);
  color: var(--text-muted);
}

.line-item-net-strip {
  display: flex;
  align-items: center;
  justify-content: space-between;
  border: 1px solid var(--accent);
  border-radius: 8px;
  background: var(--accent-soft);
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 600;
  color: var(--wood-dark);
  margin-bottom: 0;
}

.line-item-net-value {
  font-size: 16px;
  font-weight: 700;
  color: var(--text);
}

.estimate-totals-attached {
  border-top: 2px solid var(--border);
  margin-top: 20px;
  padding-top: 18px;
}

/* --------------------------------- Print --------------------------------- */

.print-modal {
  max-width: 780px;
  width: 100%;
  max-height: 90vh;
  overflow-y: auto;
  padding: 0;
}

.print-modal-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 16px 24px;
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  background: var(--surface);
  z-index: 2;
}

.print-doc {
  padding: 24px;
  color: #1c1c1c;
  background: #fff;
}

.est-frame {
  border: 1.5px solid #000;
  padding: 26px 30px;
}

.est-title {
  text-align: center;
  font-size: 10px;
  font-weight: 700;
  letter-spacing: 0.1em;
  margin-bottom: 6px;
}

.est-parties {
  position: relative;
  border: 2px solid #000;
  padding: 6px 8px;
}

.est-parties::after {
  content: '';
  position: absolute;
  top: 0;
  bottom: 0;
  left: 50%;
  border-left: 2px solid #000;
  pointer-events: none;
}

.est-from-to {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  font-size: 14.5px;
  font-weight: 600;
}

.est-from-to > span {
  flex: 1;
}

.est-from-to-body {
  display: flex;
  justify-content: space-between;
  gap: 24px;
  margin-bottom: 20px;
}

.est-company,
.est-customer {
  flex: 1;
  font-size: 14.5px;
  line-height: 1.6;
}

.est-company {
  display: flex;
  align-items: flex-start;
  gap: 12px;
}

.est-company-logo {
  max-width: 90px;
  max-height: 60px;
  object-fit: contain;
  flex-shrink: 0;
}

.est-company-text {
  flex: 1;
}

.est-customer {
  text-align: left;
}

.est-customer > div {
  margin-left: 24px;
}

.est-customer > .est-customer-label {
  margin-left: 0;
  font-weight: 600;
}

.est-company .name,
.est-customer .name {
  font-weight: 900;
}

.est-meta {
  display: flex;
  justify-content: space-between;
  font-size: 14.5px;
  font-weight: 700;
  padding: 5px 0;
}

.est-table {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}

.est-table th,
.est-table td {
  border: 1px solid #000;
  padding: 2px 0;
  text-align: right;
  vertical-align: top;
}

.est-table th {
  background: #fff;
  color: #000;
  font-weight: 700;
  font-size: 14px;
  text-transform: none;
  letter-spacing: normal;
  white-space: normal;
}

.est-table .text-right {
  text-align: right;
}

.est-table thead th,
.est-table tbody td,
.est-table thead th.text-right,
.est-table tbody td.text-right {
  text-align: center;
}

.est-table tbody td {
  border-top: none;
  border-bottom: none;
}

.est-table tfoot tr + tr > td {
  border-top: none;
}

.est-table tfoot tr:not(:last-child) > td {
  border-bottom: none;
}

.est-table tfoot tr > td:last-child {
  text-align: center;
}

.est-dims {
  color: #555;
  font-size: 13.5px;
  margin-top: 3px;
}

.est-unit-suffix {
  color: #777;
  font-size: 12.5px;
  margin-left: 3px;
}

.est-table tfoot .grand td {
  font-weight: 700;
}

.est-signature {
  margin-top: 60px;
  display: flex;
  justify-content: flex-end;
}

.est-signature-inner {
  width: 220px;
  text-align: center;
}

.est-signature-line {
  border-top: 2px solid #000;
  margin-bottom: 6px;
}

.est-thanks {
  text-align: center;
  font-style: italic;
  font-size: 14.5px;
  margin-top: 20px;
  color: #333;
}

@media print {
  body * {
    visibility: hidden;
  }
  .print-area,
  .print-area * {
    visibility: visible;
  }
  .print-area {
    position: absolute;
    top: 0;
    left: 0;
    width: 100%;
  }
  .no-print {
    display: none !important;
  }
}

/* -------------------------------- Logo preview ------------------------------- */

.logo-preview {
  width: 120px;
  height: 90px;
  flex-shrink: 0;
  border: 1px dashed var(--border);
  border-radius: 10px;
  background: var(--surface-2);
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
}

.logo-preview img {
  max-width: 100%;
  max-height: 100%;
  object-fit: contain;
}

.logo-preview-empty {
  font-size: 12px;
  color: var(--text-muted);
}

.print-doc-logo {
  max-width: 140px;
  max-height: 70px;
  object-fit: contain;
  margin-bottom: 10px;
}

/* =======================================================================
   Web (Laravel) additions
   ======================================================================= */

[hidden] {
  display: none !important;
}

.hint {
  font-size: 12.5px;
  color: var(--text-muted);
  line-height: 1.5;
}

.flash {
  background: var(--success-soft);
  color: var(--success);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13.5px;
  font-weight: 600;
  margin-bottom: 18px;
}

.flash-error,
.errors-box {
  background: var(--danger-soft);
  color: var(--danger);
  border-radius: 8px;
  padding: 10px 14px;
  font-size: 13.5px;
  margin-bottom: 18px;
}

.errors-box ul {
  margin: 0;
  padding-left: 18px;
}

form.inline {
  display: inline;
}

a.btn {
  text-decoration: none;
}

.login-error ul {
  margin: 0;
  padding-left: 18px;
}

.field textarea {
  resize: vertical;
}

.field-error {
  color: var(--danger);
  font-size: 12px;
}

.sidebar form {
  margin: 0;
}

.nav-item svg {
  display: block;
}

/* ---- Standalone print page ---- */

.print-body {
  background: #e9e5de;
  min-height: 100vh;
}

.print-toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 14px 24px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 5;
}

.print-sheet {
  max-width: 190mm;
  min-height: 128.5mm;
  margin: 24px auto 40px;
  background: #fff;
  box-shadow: var(--shadow);
}

@page {
  size: A4 portrait;
  margin: 10mm;
}

.print-sheet .print-doc {
  padding: 0;
}

.print-sheet .est-frame {
  padding: 12px 20px;
}

.print-sheet .est-from-to-body {
  margin-bottom: 0;
}

.print-sheet .est-signature {
  margin-top: 15px;
}

.print-sheet .est-thanks {
  margin-top: 8px;
}

@media print {
  .print-body {
    background: #fff;
  }
  .print-sheet {
    margin: 0;
    box-shadow: none;
    max-width: none;
  }
}

/* ---- Small screens: stack the sidebar on top ---- */

@media (max-width: 900px) {
  .app-shell {
    flex-direction: column;
    height: auto;
    min-height: 100vh;
    overflow: visible;
  }
  .sidebar {
    width: auto;
    padding: 10px 12px;
    flex-direction: column;
  }
  .brand {
    padding: 2px 4px 10px;
  }
  .nav {
    flex-direction: row;
    flex-wrap: wrap;
    flex: none;
  }
  .sidebar-footer {
    flex-direction: row;
    align-items: center;
    justify-content: space-between;
    margin-top: 10px;
  }
  .sidebar-footer .btn-block {
    width: auto;
  }
  .content {
    padding: 18px 14px 40px;
    overflow: visible;
  }
  .grid-2,
  .grid-3,
  .grid-4 {
    grid-template-columns: 1fr;
  }
  .page-header {
    flex-direction: column;
  }
}

/* ---- polish ---- */
.grid > * {
  min-width: 0;
}

.field input,
.field select,
.field textarea {
  width: 100%;
  min-width: 0;
}

.est-signature {
  font-size: 14.5px;
}

.toolbar .pill-input {
  min-width: 280px;
}
