@import url('https://fonts.googleapis.com/css2?family=Outfit:wght@300;400;500;600;700&display=swap');

:root {
  --primary: #6d28d9;
  --background: #07040c;
  --panel: rgba(255,255,255,.04);
  --border: rgba(255,255,255,.09);
  --muted: rgba(255,255,255,.56);
  --radius: 8px;
}

* { box-sizing: border-box; }
body {
  margin: 0;
  max-width: 100vw;
  overflow-x: hidden;
  background: var(--background);
  color: #fff;
  font-family: Outfit, Arial, sans-serif;
}

button, input, select, textarea { font: inherit; }
button, a { cursor: pointer; text-decoration: none; }
h1, h2, h3 { line-height: 1.15; margin: 0 0 1rem; }

.btn-primary, .btn-secondary, .icon-button, .danger-button {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: .5rem;
  border: 0;
  border-radius: var(--radius);
  color: #fff;
  font-weight: 700;
}
.btn-primary { background: var(--primary); padding: .75rem 1.4rem; }
.btn-secondary { background: rgba(255,255,255,.06); border: 1px solid var(--border); padding: .7rem 1rem; }
.compact { padding: .55rem .8rem; font-size: .85rem; }

.login-shell {
  min-height: 100vh;
  display: grid;
  place-items: center;
  padding: 1rem;
}
.login-card {
  width: min(100%, 420px);
  padding: 2rem;
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.login-icon {
  width: 54px;
  height: 54px;
  display: grid;
  place-items: center;
  margin-bottom: 1rem;
  border-radius: var(--radius);
  background: var(--primary);
}
.login-card p, .panel-header p, .panel-title p { color: var(--muted); margin: 0; }
.login-error {
  margin-bottom: 1rem;
  padding: .75rem;
  color: #fecdd3;
  background: rgba(225,29,72,.13);
  border: 1px solid rgba(225,29,72,.24);
  border-radius: var(--radius);
}

.app-shell {
  max-width: 1200px;
  margin: 0 auto;
  padding: 2rem 2rem 4rem;
}
.panel-header, .control-row, .dashboard-grid, .quote-editor-grid {
  display: grid;
  gap: 1rem;
}
.panel-header {
  grid-template-columns: minmax(0,1fr) auto;
  align-items: center;
  margin-bottom: 1.25rem;
}
.panel-header h1 { font-size: 2.25rem; }
.header-actions, .quote-toolbar-actions {
  display: flex;
  flex-wrap: wrap;
  justify-content: flex-end;
  gap: .75rem;
}
.control-row {
  grid-template-columns: minmax(280px,1fr) 110px 110px;
  margin-bottom: 1rem;
}
.search-box, .stat-card, .work-panel, .customer-form {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: var(--radius);
}
.search-box {
  display: flex;
  align-items: center;
  gap: .65rem;
  padding: .8rem 1rem;
  color: var(--muted);
}
.search-box input, .customer-form input, .field input, .field select, .field textarea {
  width: 100%;
  border: 1px solid rgba(255,255,255,.1);
  border-radius: var(--radius);
  background: rgba(255,255,255,.045);
  color: #fff;
  outline: none;
}
.search-box input { border: 0; background: transparent; padding: 0; }
.customer-form input, .field input, .field select, .field textarea { padding: .75rem; }
.field textarea { min-height: 108px; resize: vertical; line-height: 1.45; }
.field select option { color: #111; }
.field { display: flex; flex-direction: column; gap: .35rem; margin-bottom: .75rem; }
.field span, .line-total span { color: var(--muted); font-size: .78rem; font-weight: 700; }

.stat-card { padding: .7rem .9rem; text-align: right; }
.stat-card strong { display: block; font-size: 1.05rem; }
.stat-card span { color: rgba(255,255,255,.48); font-size: .72rem; font-weight: 800; text-transform: uppercase; }
.customer-form {
  display: grid;
  grid-template-columns: repeat(3,minmax(0,1fr));
  gap: .8rem;
  margin-bottom: 1rem;
  padding: 1rem;
}
.customer-form button { grid-column: span 3; }
.dashboard-grid { grid-template-columns: 330px minmax(0,1fr); align-items: start; }
.work-panel { padding: 1rem; }
.customer-panel, .quotes-panel { max-height: calc(100vh - 245px); overflow: auto; }
.panel-title { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin-bottom: .8rem; }
.panel-title h2 { margin: 0; font-size: 1.05rem; }
.panel-title span { color: var(--muted); font-weight: 800; }
.panel-actions { display: flex; align-items: center; justify-content: flex-end; gap: .55rem; flex-wrap: wrap; }
.customer-list, .quote-list, .item-list { display: flex; flex-direction: column; gap: .55rem; }
.customer-entry {
  display: grid;
  grid-template-columns: auto minmax(0,1fr);
  align-items: center;
  gap: .45rem;
  border-radius: var(--radius);
  padding: 0 .55rem 0 0;
}
.select-check {
  width: 34px;
  height: 34px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  background: rgba(255,255,255,.035);
  border: 1px solid rgba(255,255,255,.08);
}
.select-check input {
  width: 16px;
  height: 16px;
  accent-color: var(--primary);
  cursor: pointer;
}
.customer-row {
  width: 100%;
  display: grid;
  grid-template-columns: auto minmax(0,1fr) auto;
  align-items: center;
  gap: .7rem;
  padding: .7rem;
  border: 0;
  border-radius: var(--radius);
  color: #fff;
  background: transparent;
  text-align: left;
}
.customer-row:hover, .customer-row.active { background: rgba(124,58,237,.18); }
.customer-entry:has(.customer-row.active) {
  background: rgba(124,58,237,.18);
}
.customer-entry:has(.customer-row.active) .customer-row {
  background: transparent;
}
.avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  border-radius: var(--radius);
  color: var(--primary);
  background: rgba(109,40,217,.16);
}
.row-main { min-width: 0; }
.row-main strong, .row-main small { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.row-main small, .quote-row small { color: rgba(255,255,255,.52); font-size: .8rem; }
.row-count { color: rgba(255,255,255,.65); font-weight: 800; }
.quote-title { align-items: flex-start; }
.quote-list-head, .quote-row {
  display: grid;
  grid-template-columns: minmax(220px,1.5fr) minmax(140px,.8fr) minmax(130px,.7fr) 98px;
  gap: .8rem;
  align-items: center;
}
.quote-list-head {
  padding: .2rem .75rem .65rem;
  color: rgba(255,255,255,.45);
  font-size: .75rem;
  font-weight: 800;
  text-transform: uppercase;
}
.quote-row {
  padding: .75rem;
  border-radius: var(--radius);
  background: rgba(255,255,255,.035);
  border: 1px solid rgba(255,255,255,.06);
}
.quote-subject { display: flex; gap: .55rem; min-width: 0; }
.quote-subject strong, .quote-customer { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.quote-total { color: #fda4af; white-space: nowrap; }
.icon-button { width: 38px; height: 38px; background: var(--primary); }
.quote-actions {
  display: flex;
  justify-content: flex-end;
  gap: .45rem;
}
.small-danger {
  width: auto;
  min-width: 44px;
  height: 38px;
  padding: 0 .65rem;
  color: #fecdd3;
  background: rgba(225,29,72,.14);
  border: 1px solid rgba(225,29,72,.28);
}
.danger-outline {
  color: #fecdd3;
  border-color: rgba(225,29,72,.35);
  background: rgba(225,29,72,.12);
}
.empty-state { padding: 1rem; color: var(--muted); border-radius: var(--radius); background: rgba(255,255,255,.03); }

.quote-screen { min-height: 100vh; }
.quote-toolbar {
  position: sticky;
  top: 0;
  z-index: 20;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 1rem;
  padding: .9rem 1rem;
  background: rgba(7,4,12,.96);
  border-bottom: 1px solid var(--border);
}
.quote-editor-grid {
  grid-template-columns: minmax(340px,440px) minmax(0,1fr);
  align-items: start;
  max-width: 1280px;
  margin: 0 auto;
  padding: 1rem;
}
.quote-form-panel {
  position: sticky;
  top: 82px;
  max-height: calc(100vh - 100px);
  overflow: auto;
}
.currency-tabs {
  display: grid;
  grid-template-columns: repeat(3,1fr);
  gap: .45rem;
  margin-bottom: 1rem;
}
.currency-tabs button {
  padding: .65rem;
  border: 0;
  border-radius: var(--radius);
  color: rgba(255,255,255,.68);
  background: rgba(255,255,255,.05);
}
.currency-tabs button.active { color: #fff; background: var(--primary); }
.items-head { display: flex; justify-content: space-between; align-items: center; gap: 1rem; margin: .25rem 0 .75rem; }
.items-head h3 { margin: 0; font-size: 1rem; }
.item-card {
  display: grid;
  grid-template-columns: repeat(6,minmax(0,1fr));
  gap: .65rem;
  padding: .8rem;
  border-radius: var(--radius);
  background: rgba(255,255,255,.035);
  border: 1px solid rgba(255,255,255,.06);
}
.span-2 { grid-column: span 3; }
.item-card .field:nth-of-type(1),
.item-card .field:nth-of-type(2) {
  grid-column: span 3;
}
.item-card .field:nth-of-type(3) {
  grid-column: span 2;
}
.item-card .field:nth-of-type(4) {
  grid-column: span 2;
}
.item-card .field:nth-of-type(5) {
  grid-column: span 2;
}
.line-total { display: flex; flex-direction: column; justify-content: end; gap: .35rem; grid-column: span 5; }
.line-total small { color: rgba(255,255,255,.5); font-size: .75rem; }
.danger-button { width: 38px; height: 38px; align-self: end; justify-self: end; color: #fda4af; background: rgba(225,29,72,.12); }
.total-box, .proforma-totals { margin-top: 1rem; display: flex; flex-direction: column; gap: .45rem; }
.total-box div, .proforma-totals div { display: flex; justify-content: space-between; gap: 1rem; }
.total-box div:last-child strong, .proforma-totals div:last-child strong { color: #e11d48; }
.quote-preview-panel { overflow-x: auto; }
.proforma-page {
  width: min(100%,800px);
  min-width: 760px;
  min-height: 1120px;
  margin: 0 auto;
  padding: 40px;
  background: #fff;
  color: #000;
  box-shadow: 0 12px 35px rgba(0,0,0,.25);
}
.proforma-header, .proforma-meta { display: flex; justify-content: space-between; gap: 2rem; }
.proforma-header { margin-bottom: 40px; }
.brand-block { display: flex; align-items: center; gap: 15px; }
.mir-logo { color: #e11d48; font-size: 3rem; font-weight: 900; }
.brand-block p, .proforma-meta p { margin: .25rem 0; font-size: .82rem; line-height: 1.25; }
.proforma-header h1 { margin: 0; font-size: 2.5rem; }
.proforma-meta { margin-bottom: 30px; font-size: .9rem; align-items: flex-start; }
.proforma-meta-info { flex: 1; min-width: 0; }
.proforma-meta-date { min-width: 135px; text-align: right; }
.proforma-stamp { width: 180px; display: grid; place-items: center; flex-shrink: 0; }
.proforma-stamp img { width: 100%; height: auto; object-fit: contain; }
.proforma-table { width: 100%; border-collapse: collapse; }
.proforma-table th, .proforma-table td { border: 1px solid #111; padding: 8px; }
.proforma-table th { background: #f5f5f5; }
.proforma-table td:not(:first-child), .proforma-table th:not(:first-child) { text-align: right; }
.proforma-totals { width: 280px; margin-left: auto; }
.proforma-totals div { padding: .35rem 0; border-bottom: 1px solid #ddd; }
.proforma-notes { clear: both; margin-top: 1.25rem; padding: .75rem .9rem; border: 1px solid #111; }
.proforma-notes h3 { margin: 0 0 .4rem; font-size: .92rem; }
.proforma-notes ul { margin: 0; padding-left: 1.1rem; }
.proforma-notes li { margin: .2rem 0; font-size: .84rem; line-height: 1.35; }

body.pdf-export .proforma-page {
  width: 800px !important;
  min-width: 800px !important;
  min-height: 1120px !important;
  padding: 40px !important;
  box-shadow: none !important;
}

body.pdf-export .proforma-header,
body.pdf-export .proforma-meta {
  display: flex !important;
  flex-direction: row !important;
  justify-content: space-between !important;
  align-items: flex-start !important;
}

body.pdf-export .proforma-table {
  display: table !important;
  width: 100% !important;
  border-collapse: collapse !important;
}

body.pdf-export .proforma-table thead {
  display: table-header-group !important;
}

body.pdf-export .proforma-table tbody {
  display: table-row-group !important;
}

body.pdf-export .proforma-table tr {
  display: table-row !important;
  border-radius: 0 !important;
}

body.pdf-export .proforma-table th,
body.pdf-export .proforma-table td {
  display: table-cell !important;
  width: auto !important;
  border: 1px solid #111 !important;
}

body.pdf-export .proforma-table td::before {
  content: none !important;
}

body.pdf-export .proforma-totals {
  width: 280px !important;
  margin-left: auto !important;
}

@media (max-width: 860px) {
  .app-shell { padding-left: 1rem; padding-right: 1rem; }
  .panel-header, .control-row, .dashboard-grid, .quote-editor-grid { grid-template-columns: 1fr; }
  .panel-header h1 { font-size: 1.75rem; }
  .header-actions, .quote-toolbar, .quote-toolbar-actions { width: 100%; }
  .header-actions .btn-primary, .header-actions .btn-secondary, .quote-toolbar .btn-primary, .quote-toolbar .btn-secondary { flex: 1; }
  .customer-form { grid-template-columns: 1fr; }
  .customer-form button { grid-column: auto; }
  .customer-panel, .quotes-panel, .quote-form-panel { max-height: none; position: static; }
  .quote-list-head { display: none; }
  .quote-row { grid-template-columns: minmax(0,1fr) auto; }
  .quote-customer, .quote-total { grid-column: 1; }
  .quote-actions { grid-column: 2; grid-row: 1 / span 3; flex-direction: column; }
  .icon-button, .small-danger { width: 48px; min-width: 48px; padding: 0; }
  .quote-actions .select-check { width: 48px; height: 38px; }
  .quote-editor-grid { padding: .75rem; }
  .item-card { grid-template-columns: repeat(2,minmax(0,1fr)); }
  .item-card .field:nth-of-type(1),
  .item-card .field:nth-of-type(2),
  .item-card .field:nth-of-type(5) {
    grid-column: 1 / -1;
  }
  .item-card .field:nth-of-type(3),
  .item-card .field:nth-of-type(4) {
    grid-column: span 1;
  }
  .items-head { position: sticky; top: 0; z-index: 5; margin: 0 -.15rem .75rem; padding: .65rem .15rem; background: var(--background); }
  .span-2, .line-total { grid-column: 1 / -1; }
  .danger-button { grid-column: 2; justify-self: end; }
  .quote-preview-panel { margin: 0 -.75rem; padding: 0 .75rem; overflow-x: visible; }
  .proforma-page { width: 100%; min-width: 0; min-height: auto; padding: 22px; box-shadow: none; }
  .proforma-header, .proforma-meta { flex-direction: column; gap: 1rem; }
  .proforma-header { margin-bottom: 26px; }
  .brand-block { align-items: flex-start; }
  .mir-logo { font-size: 2.35rem; }
  .proforma-header h1 { font-size: 1.85rem; }
  .brand-block p, .proforma-meta p { font-size: .78rem; }
  .proforma-table, .proforma-table tbody, .proforma-table tr, .proforma-table td { display: block; width: 100%; }
  .proforma-table thead { display: none; }
  .proforma-table tr { margin-bottom: .8rem; border: 1px solid #111; border-radius: 8px; overflow: hidden; }
  .proforma-table td { display: flex; justify-content: space-between; gap: 1rem; border: 0; border-bottom: 1px solid #ddd; text-align: right; padding: 10px 12px; }
  .proforma-table td:last-child { border-bottom: 0; }
  .proforma-table td::before { content: attr(data-label); color: #111; font-weight: 700; text-align: left; }
  .proforma-stamp { width: 155px; align-self: center; }
  .proforma-meta-date { min-width: 0; text-align: left; }
  .proforma-totals { width: 100%; }
}

@media print {
  body { background: #fff !important; }
  .no-print, .quote-form-panel { display: none !important; }
  .quote-editor-grid, .quote-preview-panel { display: block; padding: 0; overflow: visible; }
  .proforma-page { min-width: 0; width: 100%; min-height: 0; box-shadow: none; padding: 0; }
}
