:root {
  --ink: #291b2d;
  --muted: #6e6470;
  --purple: #5f2c68;
  --purple-deep: #291230;
  --purple-soft: #f2e7f4;
  --orange: #ed7b48;
  --orange-soft: #fff0e8;
  --green: #23845f;
  --green-soft: #e8f7f0;
  --red: #b44848;
  --red-soft: #fff0ef;
  --line: #e6dfe7;
  --background: #f8f5f5;
  --panel: #ffffff;
  --shadow: 0 18px 50px rgba(54, 27, 55, .09);
  color-scheme: light;
  font: 17px/1.5 Inter, ui-sans-serif, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }
html, body { min-height: 100%; }
body { margin: 0; color: var(--ink); background: radial-gradient(circle at 85% 0, #fff4ed 0, transparent 32%), var(--background); }
button, input, select, textarea { font: inherit; }
button { cursor: pointer; }
[hidden] { display: none !important; }

.auth-screen { min-height: 100vh; display: grid; place-items: center; padding: 30px; background: linear-gradient(135deg, #2a1231, #60306a 57%, #ed7b48); }
.auth-card { width: min(570px, 100%); padding: 38px; border-radius: 28px; background: rgba(255,255,255,.97); box-shadow: 0 30px 90px rgba(18, 5, 20, .35); }
.auth-card > .brand-mark { margin-bottom: 20px; }
.auth-card h1 { margin: 4px 0 8px; font-size: 2rem; line-height: 1.12; }
.auth-card p { color: var(--muted); }
.auth-card form { display: grid; gap: 17px; margin-top: 28px; }
.auth-card footer { margin-top: 24px; color: var(--muted); font-size: .8rem; }

.brand-mark { width: 65px; height: 65px; display: grid; place-items: center; border-radius: 19px; background: linear-gradient(140deg, var(--purple), #93489c 62%, var(--orange)); color: #fff; font-weight: 900; letter-spacing: -.08em; box-shadow: 0 12px 28px rgba(94, 43, 104, .25); }
.brand-mark.small { width: 50px; height: 50px; border-radius: 15px; font-size: .9rem; }

.app { min-height: 100vh; display: grid; grid-template-columns: 285px minmax(0, 1fr); }
aside { position: sticky; top: 0; height: 100vh; display: flex; flex-direction: column; color: #fff; background: linear-gradient(180deg, #32153a, #211026); box-shadow: 12px 0 40px rgba(35, 14, 41, .12); z-index: 2; }
aside > header { display: flex; align-items: center; gap: 13px; padding: 24px 20px; }
aside > header div { display: grid; }
aside > header b { font-size: 1.12rem; }
aside > header small { color: #cdbcd0; }
aside nav { display: grid; gap: 7px; padding: 15px; }
aside nav button { display: flex; align-items: center; gap: 13px; width: 100%; min-height: 52px; padding: 11px 14px; border: 0; border-radius: 14px; color: #ddcede; background: transparent; text-align: left; font-weight: 760; }
aside nav button span { width: 28px; font-size: 1.25rem; text-align: center; }
aside nav button:hover, aside nav button.active { color: #fff; background: linear-gradient(90deg, rgba(237,123,72,.22), rgba(164,83,174,.34)); }
aside nav button.active { box-shadow: inset 4px 0 var(--orange); }
aside > footer { margin-top: auto; display: grid; grid-template-columns: 42px 1fr 36px; align-items: center; gap: 10px; padding: 19px; border-top: 1px solid rgba(255,255,255,.12); }
aside > footer > div { width: 42px; height: 42px; display: grid; place-items: center; border-radius: 13px; background: #8d4697; font-weight: 900; }
aside > footer span { min-width: 0; display: grid; }
aside > footer small { overflow: hidden; color: #cabacb; font-size: .68rem; text-overflow: ellipsis; }
aside > footer button { border: 0; color: #fff; background: transparent; font-size: 1.25rem; }

.workspace { min-width: 0; }
.topbar { height: 84px; display: flex; align-items: center; justify-content: space-between; gap: 20px; padding: 0 35px; background: rgba(255,255,255,.8); border-bottom: 1px solid rgba(110,90,110,.12); backdrop-filter: blur(18px); }
.topbar > div { display: grid; }
.topbar small { color: var(--orange); font-weight: 900; text-transform: uppercase; letter-spacing: .08em; }
.topbar b { font-size: .95rem; }
.notification { position: relative; min-width: 48px; min-height: 48px; border: 1px solid var(--line); border-radius: 15px; background: #fff; }
.notification em { position: absolute; right: -6px; top: -7px; min-width: 22px; padding: 2px 6px; border-radius: 99px; color: #fff; background: var(--red); font-size: .68rem; font-style: normal; font-weight: 900; }

.view { display: none; padding: 35px clamp(24px, 4vw, 64px) 70px; }
.view.active { display: block; }
.page-title { display: flex; align-items: flex-end; justify-content: space-between; gap: 25px; margin-bottom: 28px; }
.page-title small, .panel header small, .metric small { color: #8d7d8f; font-size: .73rem; font-weight: 900; letter-spacing: .12em; }
.page-title h1 { margin: 3px 0 4px; font-size: clamp(2rem, 3.5vw, 3rem); line-height: 1.08; }
.page-title p { margin: 0; color: var(--muted); }

button { min-height: 46px; padding: 10px 17px; border: 1px solid var(--line); border-radius: 13px; color: var(--ink); background: #fff; font-weight: 800; }
button:hover { border-color: #cdbdce; transform: translateY(-1px); }
button.primary { color: #fff; border-color: transparent; background: linear-gradient(135deg, var(--orange), #d8663d); box-shadow: 0 11px 24px rgba(237,123,72,.24); }
button:disabled { opacity: .5; cursor: not-allowed; transform: none; }
.button-row { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 9px; }

.metric-grid { display: grid; grid-template-columns: repeat(5, minmax(0, 1fr)); gap: 15px; margin-bottom: 22px; }
.metric { min-height: 145px; padding: 22px; border: 1px solid rgba(95,44,104,.08); border-radius: 22px; background: var(--panel); box-shadow: var(--shadow); }
.metric span { width: 42px; height: 42px; display: grid; place-items: center; margin-bottom: 15px; border-radius: 13px; background: var(--purple-soft); font-size: 1.3rem; }
.metric b { display: block; font-size: 1.8rem; line-height: 1.1; }
.metric p { margin: 5px 0 0; color: var(--muted); font-size: .78rem; }
.metric.alert span { color: var(--red); background: var(--red-soft); }
.metric.money span { color: var(--green); background: var(--green-soft); }

.dashboard-grid, .two-columns { display: grid; grid-template-columns: 1.2fr .8fr; gap: 22px; }
.panel, .table-panel { border: 1px solid rgba(95,44,104,.1); border-radius: 23px; background: var(--panel); box-shadow: var(--shadow); overflow: hidden; }
.panel > header { padding: 21px 24px; border-bottom: 1px solid var(--line); }
.panel h2 { margin: 2px 0 0; font-size: 1.25rem; }
.stack-list { display: grid; }
.stack-item { display: grid; grid-template-columns: 46px minmax(0,1fr) auto; align-items: center; gap: 13px; min-height: 79px; padding: 14px 22px; border-bottom: 1px solid #eee9ef; }
.stack-item:last-child { border-bottom: 0; }
.stack-item > span:first-child { width: 43px; height: 43px; display: grid; place-items: center; border-radius: 13px; color: var(--purple); background: var(--purple-soft); font-size: 1.1rem; }
.stack-item > div { min-width: 0; display: grid; }
.stack-item b { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; }
.stack-item small { color: var(--muted); }
.stack-item em { color: var(--muted); font-size: .75rem; font-style: normal; text-align: right; }
.empty { padding: 30px 22px; color: var(--muted); text-align: center; }

.filterbar { display: grid; grid-template-columns: minmax(280px, 1fr) 220px 200px; gap: 12px; margin-bottom: 17px; }
input, select, textarea { width: 100%; min-height: 49px; padding: 11px 13px; border: 1px solid #d8cfd9; border-radius: 12px; color: var(--ink); background: #fff; outline: none; }
input:focus, select:focus, textarea:focus { border-color: #9850a2; box-shadow: 0 0 0 4px rgba(152,80,162,.12); }
textarea { min-height: 105px; resize: vertical; }
label { display: grid; gap: 6px; color: #4c3e4e; font-size: .82rem; font-weight: 800; }
label small { color: var(--muted); font-size: .72rem; font-weight: 500; }
.company-lookup { display: grid; grid-template-columns: minmax(0, 1fr) auto; gap: 9px; }
.company-lookup button { min-width: 125px; }
.company-lookup-status { min-height: 1.35em; }
.company-lookup-status.searching { color: var(--purple); font-weight: 750; }
.company-lookup-status.success-text { color: var(--green); font-weight: 750; }
.company-lookup-status.warning-text { color: #9b521f; font-weight: 750; }
.company-lookup-status.error-text { color: var(--red); font-weight: 750; }
.customer-logo-editor { display: flex; align-items: center; gap: 16px; padding: 14px; border: 1px solid var(--line); border-radius: 16px; background: #fbf8fb; }
.customer-logo-preview, .customer-logo { flex: 0 0 auto; width: 70px; height: 70px; display: grid; place-items: center; overflow: hidden; border: 1px solid #ddd3df; border-radius: 15px; color: var(--purple); background: #fff; font-size: .74rem; font-weight: 900; }
.customer-logo-preview img, .customer-logo img { width: 100%; height: 100%; object-fit: contain; }
.customer-logo-actions { display: flex; flex-wrap: wrap; gap: 9px; }
.customer-logo { width: 48px; height: 48px; border-radius: 12px; font-size: 1rem; }
.customer-identity { display: flex; align-items: center; gap: 12px; min-width: 240px; }
.customer-identity > div { min-width: 0; }

table { width: 100%; border-collapse: collapse; }
th { padding: 14px 17px; color: #786a7a; background: #faf7fa; font-size: .7rem; letter-spacing: .08em; text-align: left; text-transform: uppercase; }
td { padding: 17px; border-top: 1px solid #eee8ef; vertical-align: middle; }
td b, td small { display: block; }
td small { color: var(--muted); }
.row-actions { text-align: right; white-space: nowrap; }
.row-actions button { min-height: 38px; padding: 7px 11px; font-size: .75rem; }

.badge { display: inline-flex; align-items: center; width: fit-content; padding: 5px 9px; border-radius: 99px; color: var(--purple); background: var(--purple-soft); font-size: .7rem; font-weight: 900; text-transform: uppercase; }
.badge.active, .badge.issued { color: var(--green); background: var(--green-soft); }
.badge.suspended, .badge.overdue, .badge.read_only { color: var(--red); background: var(--red-soft); }
.badge.friend, .badge.grace { color: #a34f24; background: var(--orange-soft); }

.card-grid { display: grid; grid-template-columns: repeat(3, minmax(0,1fr)); gap: 18px; }
.installation-card { min-height: 245px; padding: 22px; border: 1px solid rgba(95,44,104,.1); border-radius: 23px; background: #fff; box-shadow: var(--shadow); }
.installation-card header { display: flex; justify-content: space-between; gap: 12px; }
.installation-card h2 { margin: 3px 0 0; font-size: 1.2rem; }
.installation-card > p { min-height: 26px; color: var(--purple); font-weight: 800; }
.installation-card dl { display: grid; gap: 8px; margin: 18px 0; }
.installation-card dl div { display: flex; justify-content: space-between; gap: 12px; }
.installation-card dt { color: var(--muted); }
.installation-card dd { margin: 0; font-weight: 800; text-align: right; }
.installation-card footer { display: flex; gap: 8px; }
.installation-card footer button { flex: 1; }

.contracts-panel { margin-top: 22px; }
.table-panel.flat { border: 0; border-radius: 0; box-shadow: none; }
.timeline { position: relative; display: grid; gap: 12px; max-width: 980px; }
.timeline-item { display: grid; grid-template-columns: 155px 38px minmax(0, 1fr); gap: 16px; align-items: start; }
.timeline-item > time { padding-top: 13px; color: var(--muted); font-size: .78rem; text-align: right; }
.timeline-item > span { width: 38px; height: 38px; display: grid; place-items: center; border: 4px solid var(--background); border-radius: 99px; color: #fff; background: var(--purple); z-index: 1; }
.timeline-item > div { padding: 13px 17px; border: 1px solid var(--line); border-radius: 15px; background: #fff; }
.timeline-item b, .timeline-item small { display: block; }
.timeline-item small { color: var(--muted); }

.toast { position: fixed; right: 25px; top: 100px; max-width: 430px; padding: 15px 19px; border-radius: 14px; color: #fff; background: var(--green); box-shadow: 0 20px 50px rgba(0,0,0,.2); font-weight: 800; z-index: 20; }
.toast.error { background: var(--red); }
.error { margin: 0; padding: 11px 13px; border-radius: 11px; color: #8a2828 !important; background: var(--red-soft); font-weight: 750; }

dialog { width: min(850px, calc(100vw - 32px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: 25px; color: var(--ink); background: #fff; box-shadow: 0 30px 100px rgba(25,10,29,.35); }
dialog::backdrop { background: rgba(32,14,37,.62); backdrop-filter: blur(5px); }
dialog form > header, .result-dialog section > header { display: flex; align-items: flex-start; justify-content: space-between; padding: 23px 26px; border-bottom: 1px solid var(--line); }
dialog h2 { margin: 2px 0 0; font-size: 1.55rem; }
dialog header small { color: var(--orange); font-weight: 900; letter-spacing: .1em; }
button.close { width: 43px; min-height: 43px; padding: 0; border-radius: 99px; font-size: 1.6rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0,1fr)); gap: 16px; padding: 25px 26px; max-height: calc(100vh - 220px); overflow: auto; }
.form-grid .full { grid-column: 1 / -1; }
dialog form > .error { margin: 0 26px; }
dialog form > footer, .result-dialog footer { display: flex; justify-content: flex-end; gap: 10px; padding: 18px 26px; border-top: 1px solid var(--line); }
.result-dialog { width: min(760px, calc(100vw - 32px)); }
.result-dialog section > p { padding: 0 26px; color: var(--muted); }
.result-dialog textarea { width: calc(100% - 52px); min-height: 190px; margin: 0 26px 24px; font: .72rem/1.45 ui-monospace, SFMono-Regular, Menlo, monospace; word-break: break-all; }

@media (max-width: 1200px) {
  .metric-grid { grid-template-columns: repeat(3, 1fr); }
  .card-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 900px) {
  .app { display: block; }
  aside { position: static; width: 100%; height: auto; }
  aside > header { padding: 14px 18px; }
  aside nav { display: flex; overflow-x: auto; padding: 8px 12px 13px; }
  aside nav button { width: auto; flex: 0 0 auto; }
  aside > footer { display: none; }
  .topbar { height: auto; min-height: 76px; padding: 13px 18px; }
  .view { padding: 25px 18px 55px; }
  .dashboard-grid, .two-columns { grid-template-columns: 1fr; }
  .filterbar { grid-template-columns: 1fr 1fr; }
  .filterbar input { grid-column: 1 / -1; }
  .table-panel { overflow-x: auto; }
  table { min-width: 850px; }
}

@media (max-width: 620px) {
  :root { font-size: 16px; }
  .auth-screen { padding: 12px; }
  .auth-card { padding: 25px 20px; border-radius: 22px; }
  .topbar b { display: none; }
  .page-title { align-items: stretch; flex-direction: column; }
  .page-title > button, .button-row button { width: 100%; }
  .button-row { display: grid; grid-template-columns: 1fr; }
  .metric-grid, .card-grid, .filterbar, .form-grid { grid-template-columns: 1fr; }
  .company-lookup { grid-template-columns: 1fr; }
  .company-lookup button { width: 100%; }
  .customer-logo-editor { align-items: stretch; flex-direction: column; }
  .customer-logo-actions { display: grid; grid-template-columns: 1fr; }
  .form-grid .full, .filterbar input { grid-column: auto; }
  .metric { min-height: 125px; }
  .timeline-item { grid-template-columns: 38px 1fr; }
  .timeline-item > time { grid-column: 2; grid-row: 2; padding: 0; text-align: left; }
}
