:root {
  --bg: #f6f5f2;
  --surface: #ffffff;
  --surface-2: #faf9f7;
  --border: #e4e1da;
  --text: #1f1d1a;
  --muted: #6d6860;
  --brand: #d9622b;
  --brand-dark: #b54d1d;
  --brand-soft: #fbeee6;
  --ok: #2f8a4c;
  --ok-soft: #e5f3e9;
  --bad: #c0392b;
  --bad-soft: #f9e5e2;
  --info: #2563a8;
  --info-soft: #e4eef9;
  --radius: 10px;
  --shadow: 0 1px 2px rgba(0,0,0,.04), 0 4px 16px rgba(0,0,0,.05);
}
* { box-sizing: border-box; }
html, body { margin: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
  background: var(--bg); color: var(--text); font-size: 15px; line-height: 1.45;
}
a { color: var(--brand-dark); }
h1, h2, h3 { margin: 0 0 .5em; line-height: 1.2; }
h1 { font-size: 24px; }
h2 { font-size: 18px; }

/* layout */
.topbar {
  background: var(--surface); border-bottom: 1px solid var(--border);
  position: sticky; top: 0; z-index: 10;
}
.topbar-inner {
  max-width: 1100px; margin: 0 auto; padding: 0 16px; height: 58px;
  display: flex; align-items: center; gap: 24px;
}
.logo { font-weight: 800; font-size: 19px; letter-spacing: -.3px; text-decoration: none; color: var(--text); }
.logo span { color: var(--brand); }
.nav { display: flex; gap: 4px; flex: 1; overflow-x: auto; }
.nav a {
  padding: 8px 12px; border-radius: 8px; text-decoration: none; color: var(--muted); font-weight: 500; white-space: nowrap;
}
.nav a.active, .nav a:hover { background: var(--brand-soft); color: var(--brand-dark); }
.container { max-width: 1100px; margin: 0 auto; padding: 24px 16px 60px; }
.page-head { display: flex; align-items: center; justify-content: space-between; gap: 12px; margin-bottom: 20px; flex-wrap: wrap; }
.page-head h1 { margin: 0; }

/* cards */
.card { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); box-shadow: var(--shadow); padding: 20px; }
.card + .card { margin-top: 16px; }
.stats { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat { background: var(--surface); border: 1px solid var(--border); border-radius: var(--radius); padding: 16px; }
.stat .label { color: var(--muted); font-size: 13px; }
.stat .value { font-size: 24px; font-weight: 700; margin-top: 4px; font-variant-numeric: tabular-nums; }

/* buttons */
.btn {
  display: inline-flex; align-items: center; justify-content: center; gap: 6px;
  border: 1px solid var(--border); background: var(--surface); color: var(--text);
  padding: 9px 14px; border-radius: 8px; font-size: 14px; font-weight: 600; cursor: pointer;
  text-decoration: none; font-family: inherit;
}
.btn:hover { background: var(--surface-2); }
.btn.primary { background: var(--brand); border-color: var(--brand); color: #fff; }
.btn.primary:hover { background: var(--brand-dark); }
.btn.ok { background: var(--ok); border-color: var(--ok); color: #fff; }
.btn.danger { color: var(--bad); }
.btn.danger.solid { background: var(--bad); border-color: var(--bad); color: #fff; }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.sm { padding: 5px 10px; font-size: 13px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-row { display: flex; gap: 8px; flex-wrap: wrap; }

/* forms */
label { display: block; font-size: 13px; font-weight: 600; color: var(--muted); margin-bottom: 4px; }
input, select, textarea {
  width: 100%; padding: 9px 11px; border: 1px solid var(--border); border-radius: 8px;
  font: inherit; background: #fff; color: var(--text);
}
input:focus, select:focus, textarea:focus { outline: 2px solid var(--brand-soft); border-color: var(--brand); }
textarea { resize: vertical; min-height: 80px; }
.field { margin-bottom: 14px; }
.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 0 16px; }
.grid-3 { display: grid; grid-template-columns: repeat(3, 1fr); gap: 0 16px; }
@media (max-width: 700px) { .grid-2, .grid-3 { grid-template-columns: 1fr; } }

/* tables */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; }
th, td { text-align: left; padding: 10px 12px; border-bottom: 1px solid var(--border); vertical-align: middle; }
th { font-size: 12px; text-transform: uppercase; letter-spacing: .4px; color: var(--muted); font-weight: 600; background: var(--surface-2); }
tr.clickable { cursor: pointer; }
tr.clickable:hover td { background: var(--surface-2); }
.num { text-align: right; font-variant-numeric: tabular-nums; white-space: nowrap; }

/* items editor */
.items-table td { padding: 6px 4px; border-bottom: none; }
.items-table th { padding: 8px 4px; }
.items-table input { padding: 7px 8px; }
.items-table .c-qty { width: 80px; }
.items-table .c-unit { width: 100px; }
.items-table .c-price { width: 130px; }
.items-table .c-total { width: 120px; }
.items-table .c-del { width: 36px; }
@media (max-width: 700px) {
  .items-table thead { display: none; }
  .items-table tr { display: grid; grid-template-columns: 1fr 1fr 1fr 36px; gap: 6px; padding: 10px 0; border-bottom: 1px solid var(--border); }
  .items-table td { padding: 0; width: auto !important; }
  .items-table td.c-desc { grid-column: 1 / -1; }
  .items-table td.c-total { display: none; }
}
.totals { margin-left: auto; max-width: 340px; margin-top: 12px; }
.totals .row { display: flex; justify-content: space-between; padding: 5px 0; font-variant-numeric: tabular-nums; }
.totals .row.grand { border-top: 2px solid var(--text); margin-top: 6px; padding-top: 10px; font-size: 18px; font-weight: 700; }
.totals input { width: 110px; text-align: right; padding: 4px 8px; }

/* badges */
.badge { display: inline-block; padding: 3px 9px; border-radius: 99px; font-size: 12px; font-weight: 600; white-space: nowrap; }
.badge.taslak { background: #eeece8; color: var(--muted); }
.badge.gonderildi { background: var(--info-soft); color: var(--info); }
.badge.kabul { background: var(--ok-soft); color: var(--ok); }
.badge.red { background: var(--bad-soft); color: var(--bad); }

/* auth */
.auth-wrap { min-height: 100vh; display: grid; place-items: center; padding: 16px; }
.auth-card { width: 100%; max-width: 400px; }
.auth-card .logo { display: block; text-align: center; font-size: 28px; margin-bottom: 4px; }
.auth-card .tagline { text-align: center; color: var(--muted); margin-bottom: 24px; }
.auth-switch { text-align: center; margin-top: 16px; color: var(--muted); font-size: 14px; }

.error { background: var(--bad-soft); color: var(--bad); padding: 10px 12px; border-radius: 8px; margin-bottom: 14px; font-size: 14px; }
.muted { color: var(--muted); }
.small { font-size: 13px; }
.empty { text-align: center; padding: 40px 16px; color: var(--muted); }
.filters { display: flex; gap: 6px; flex-wrap: wrap; margin-bottom: 14px; }
.filters .btn.active { background: var(--brand-soft); border-color: var(--brand); color: var(--brand-dark); }
.link-box { display: flex; gap: 8px; }
.link-box input { font-family: ui-monospace, Menlo, monospace; font-size: 13px; }
.notice { overflow-wrap: anywhere; padding: 12px 14px; border-radius: 8px; background: var(--surface-2); border: 1px solid var(--border); margin-bottom: 14px; font-size: 14px; }
.notice.ok { background: var(--ok-soft); border-color: #bfe0c9; }
.notice.bad { background: var(--bad-soft); border-color: #efc4be; }

/* toast */
.toast {
  position: fixed; bottom: 20px; left: 50%; transform: translateX(-50%);
  background: var(--text); color: #fff; padding: 10px 18px; border-radius: 8px; font-size: 14px;
  box-shadow: var(--shadow); z-index: 100; animation: fadein .2s;
}
@keyframes fadein { from { opacity: 0; transform: translate(-50%, 8px); } }

/* modal */
.modal-bg { position: fixed; inset: 0; background: rgba(0,0,0,.35); display: grid; place-items: center; padding: 16px; z-index: 50; }
.modal { background: var(--surface); border-radius: var(--radius); padding: 22px; width: 100%; max-width: 460px; box-shadow: 0 10px 40px rgba(0,0,0,.2); }

/* quote document (shared by preview, public page & print) */
.doc { background: #fff; color: #1f1d1a; border: 1px solid var(--border); border-radius: var(--radius); padding: 40px; max-width: 820px; margin: 0 auto; }
.doc-head { display: flex; justify-content: space-between; gap: 24px; flex-wrap: wrap; border-bottom: 3px solid var(--brand); padding-bottom: 18px; margin-bottom: 22px; }
.doc-firm h2 { font-size: 22px; margin: 0 0 4px; }
.doc-firm div, .doc-meta div { font-size: 13px; color: #555; }
.doc-meta { text-align: right; }
.doc-meta .doc-title { font-size: 26px; font-weight: 800; color: var(--brand); letter-spacing: 1px; color: var(--brand); }
.doc-parties { display: flex; justify-content: space-between; gap: 24px; margin-bottom: 22px; flex-wrap: wrap; }
.doc-parties h4 { margin: 0 0 4px; font-size: 11px; text-transform: uppercase; letter-spacing: .6px; color: #888; }
.doc-subject { font-size: 17px; font-weight: 700; margin-bottom: 14px; }
.doc table th { background: #f4f2ee; }
.doc .notes { margin-top: 24px; font-size: 13px; white-space: pre-wrap; }
.doc .notes h4 { margin: 0 0 4px; font-size: 12px; text-transform: uppercase; color: #888; }
.doc-foot { margin-top: 28px; padding-top: 14px; border-top: 1px solid #e4e1da; font-size: 12px; color: #777; }
@media (max-width: 700px) {
  .doc { padding: 20px; } .doc-meta { text-align: left; }
  .doc .c-no { display: none; }
  .doc th, .doc td { padding: 8px 6px; font-size: 13px; }
  .doc th { font-size: 10px; letter-spacing: 0; }
}

@media print {
  body { background: #fff; }
  .no-print { display: none !important; }
  .container { padding: 0; max-width: none; }
  .doc { border: none; padding: 0; max-width: none; box-shadow: none; }
  .badge { border: 1px solid currentColor; }
}
