:root {
  --ink: #11110f;
  --ink-soft: #353530;
  --paper: #f4f1e9;
  --paper-deep: #e9e4d9;
  --white: #fffef9;
  --red: #e64027;
  --red-dark: #bd2d1a;
  --muted: #77746c;
  --line: #d8d2c6;
  --shadow: 0 18px 50px rgba(30, 28, 22, 0.1);
  --radius: 18px;
}

* { box-sizing: border-box; }
html { min-width: 320px; background: var(--paper); }
body {
  margin: 0;
  color: var(--ink);
  background: var(--paper);
  font-family: "Segoe UI", Arial, sans-serif;
  font-size: 15px;
}
button, input, textarea { font: inherit; }
button { color: inherit; }
button, .file-label { cursor: pointer; }
.hidden { display: none !important; }

.app-shell { min-height: 100vh; display: grid; grid-template-columns: 310px minmax(0, 1fr); }
.sidebar {
  position: fixed;
  inset: 0 auto 0 0;
  z-index: 20;
  width: 310px;
  display: flex;
  flex-direction: column;
  color: #f5f2e9;
  background: #11110f;
  border-right: 1px solid #2c2b27;
}
.brand {
  min-height: 112px;
  padding: 18px 17px;
  display: flex;
  gap: 12px;
  align-items: center;
  border-bottom: 1px solid #2b2a26;
}
.brand-mark {
  width: 54px;
  height: 54px;
  flex: 0 0 54px;
  overflow: hidden;
  border: 1px solid #555248;
  border-radius: 13px;
}
.brand-mark img { width: 100%; height: 100%; display: block; object-fit: cover; }
.brand-copy { min-width: 0; }
.brand strong { display: block; text-transform: uppercase; font-size: 11px; line-height: 1.25; letter-spacing: 0.09em; }
.brand span { display: block; margin-top: 4px; color: #b1ada3; font-size: 9px; letter-spacing: 0.1em; text-transform: uppercase; }
.brand small { display: block; margin-top: 7px; color: var(--red); font-size: 7px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }

.button {
  min-height: 44px;
  padding: 11px 16px;
  border: 1px solid transparent;
  border-radius: 11px;
  display: inline-flex;
  justify-content: center;
  align-items: center;
  gap: 8px;
  font-size: 12px;
  font-weight: 700;
  letter-spacing: 0.06em;
  text-transform: uppercase;
  transition: 0.2s ease;
}
.button:hover { transform: translateY(-1px); }
.button-primary { color: white; background: var(--red); border-color: var(--red); }
.button-primary:hover { background: var(--red-dark); border-color: var(--red-dark); }
.button-light { color: var(--ink); background: var(--white); border-color: var(--line); }
.button-light:hover { border-color: #9f9a8f; }
.button-danger { color: #a62d20; background: #fff8f5; border-color: #e9b6ad; }
.new-customer-button { margin: 22px 18px 12px; justify-content: flex-start; }
.button-icon { font-size: 21px; line-height: 0; }

.search-box { margin: 4px 18px 20px; position: relative; color: #8b887f; }
.search-box > span { position: absolute; left: 13px; top: 9px; font-size: 22px; }
.search-box input {
  width: 100%;
  height: 47px;
  padding: 0 40px;
  outline: none;
  color: white;
  background: #1d1d1a;
  border: 1px solid #33322d;
  border-radius: 11px;
}
.search-box input:focus { border-color: #777269; }
.search-box kbd { position: absolute; top: 14px; right: 12px; padding: 2px 6px; color: #706e66; background: #292824; border: 1px solid #3c3b35; border-radius: 4px; font: 10px inherit; }
.list-heading { padding: 0 21px 10px; display: flex; justify-content: space-between; color: #807d74; font-size: 10px; font-weight: 700; letter-spacing: 0.12em; text-transform: uppercase; }
.text-button { padding: 4px 0; color: var(--red); background: none; border: 0; font-size: 11px; font-weight: 700; }
.customer-list { flex: 1; min-height: 0; padding: 0 9px 15px; overflow-y: auto; }
.customer-list::-webkit-scrollbar { width: 5px; }
.customer-list::-webkit-scrollbar-thumb { background: #3d3b35; border-radius: 9px; }
.customer-list-empty { padding: 35px 18px; color: #77746c; text-align: center; font-size: 12px; line-height: 1.6; }
.letter-heading { margin: 14px 12px 6px; color: #69665e; font-size: 9px; letter-spacing: 0.2em; }
.customer-row {
  width: 100%;
  padding: 10px 11px;
  display: grid;
  grid-template-columns: 38px 1fr auto;
  gap: 10px;
  align-items: center;
  color: #dad7ce;
  background: transparent;
  border: 1px solid transparent;
  border-radius: 10px;
  text-align: left;
}
.customer-row:hover, .customer-row.active { background: #22221e; border-color: #36352f; }
.customer-row.active { box-shadow: inset 3px 0 var(--red); }
.customer-row strong { display: block; overflow: hidden; text-overflow: ellipsis; white-space: nowrap; font-size: 12px; }
.customer-row small { display: block; margin-top: 4px; color: #77746c; font-size: 10px; }
.customer-row > b { color: #69665e; font-size: 12px; font-weight: 400; }
.avatar {
  width: 38px;
  height: 38px;
  display: grid;
  place-items: center;
  flex: 0 0 auto;
  border-radius: 50%;
  color: #f0ede5;
  background: #36352f;
  font-size: 11px;
  font-weight: 800;
  letter-spacing: 0.03em;
}
.avatar.large { width: 72px; height: 72px; color: white; background: var(--ink); font-size: 18px; }
.sidebar-footer { display: grid; grid-template-columns: 1fr 1fr; border-top: 1px solid #2b2a26; }
.sidebar-footer button { min-height: 53px; color: #8c897f; background: none; border: 0; border-right: 1px solid #2b2a26; font-size: 10px; font-weight: 700; letter-spacing: 0.08em; text-transform: uppercase; }
.sidebar-footer button:hover { color: white; background: #1d1d1a; }

.main-content { grid-column: 2; min-width: 0; }
.topbar {
  min-height: 96px;
  padding: 18px 35px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 25px;
  background: rgba(244, 241, 233, 0.93);
  border-bottom: 1px solid var(--line);
  backdrop-filter: blur(15px);
}
.topbar h1 { margin: 3px 0 0; font: 700 19px Georgia, serif; }
.eyebrow { color: var(--red); font-size: 9px; font-weight: 800; letter-spacing: 0.19em; text-transform: uppercase; }
.topbar-actions { display: flex; align-items: center; gap: 12px; }
.privacy-pill { display: flex; align-items: center; gap: 7px; color: var(--muted); font-size: 11px; }
.privacy-pill i { width: 7px; height: 7px; background: #52a968; border-radius: 50%; box-shadow: 0 0 0 4px rgba(82,169,104,.13); }
.mobile-menu { display: none; border: 0; background: none; font-size: 21px; }

.dashboard { padding: 45px clamp(24px, 4vw, 62px) 65px; }
.dashboard-intro { max-width: 1120px; display: grid; grid-template-columns: 1.2fr 0.8fr; align-items: end; gap: 60px; }
.dashboard-intro h2 { margin: 13px 0 0; font: 700 clamp(45px, 6vw, 82px)/0.93 Georgia, serif; letter-spacing: -0.065em; }
.dashboard-intro h2 em { color: var(--red); font-weight: 400; }
.dashboard-intro p { max-width: 420px; margin: 0 0 6px; color: var(--muted); line-height: 1.75; }
.stat-grid { margin-top: 45px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 14px; }
.stat-card { min-height: 175px; padding: 24px; display: flex; flex-direction: column; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); }
.stat-card.dark { color: white; background: var(--ink); border-color: var(--ink); }
.stat-card span { color: var(--muted); font-size: 10px; font-weight: 800; letter-spacing: 0.13em; text-transform: uppercase; }
.stat-card.dark span, .stat-card.dark small { color: #87847b; }
.stat-card strong { margin: auto 0 2px; font: 700 58px/1 Georgia, serif; letter-spacing: -0.05em; }
.stat-card strong.date-stat { font-size: clamp(26px, 3vw, 42px); }
.stat-card small { color: var(--muted); font-size: 11px; }
.dashboard-grid { margin-top: 14px; display: grid; grid-template-columns: minmax(0, 1.4fr) minmax(300px, 0.6fr); gap: 14px; }
.panel { padding: 25px; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); }
.panel-heading { display: flex; align-items: end; justify-content: space-between; gap: 25px; }
.panel h3, .panel-heading h3, .quick-panel h3, .visit-entry h3 { margin: 6px 0 0; font: 700 23px Georgia, serif; }
.recent-list { margin-top: 22px; }
.recent-customer { width: 100%; padding: 13px 4px; display: grid; grid-template-columns: 42px 1fr auto; gap: 12px; align-items: center; background: none; border: 0; border-top: 1px solid var(--line); text-align: left; }
.recent-customer:hover strong { color: var(--red); }
.recent-customer strong { display: block; font-size: 13px; }
.recent-customer small { display: block; margin-top: 4px; color: var(--muted); font-size: 10px; }
.recent-customer > span { color: var(--muted); font-size: 10px; }
.empty-message { padding: 35px 5px; color: var(--muted); font-size: 12px; line-height: 1.6; }
.quick-panel { background: #ded8cc; }
.quick-panel h3 { margin-bottom: 25px; }
.quick-action { width: 100%; padding: 16px 0; display: grid; grid-template-columns: 30px 1fr auto; gap: 8px; background: none; border: 0; border-top: 1px solid #bdb6a9; text-align: left; }
.quick-action:last-child { border-bottom: 1px solid #bdb6a9; }
.quick-action span { color: var(--red); font-size: 9px; font-weight: 800; }
.quick-action strong { font-size: 12px; text-transform: uppercase; letter-spacing: 0.06em; }
.quick-action b { font-size: 16px; transition: transform .2s; }
.quick-action:hover b { transform: translateX(4px); }

.customer-view { padding: 35px clamp(24px, 4vw, 62px) 70px; }
.customer-header { display: grid; grid-template-columns: 1fr auto; gap: 22px; align-items: end; }
.back-button { grid-column: 1 / -1; width: max-content; padding: 0; color: var(--muted); background: none; border: 0; font-size: 11px; font-weight: 700; text-transform: uppercase; letter-spacing: .08em; }
.back-button:hover { color: var(--red); }
.customer-title { display: flex; align-items: center; gap: 17px; min-width: 0; }
.customer-title h2 { margin: 6px 0 4px; overflow: hidden; text-overflow: ellipsis; font: 700 clamp(30px, 4vw, 52px)/1 Georgia, serif; letter-spacing: -.045em; white-space: nowrap; }
.customer-title p { margin: 0; color: var(--muted); font-size: 11px; }
.customer-actions { display: flex; flex-wrap: wrap; justify-content: flex-end; gap: 8px; }
.tabs { margin: 35px 0 0; display: flex; gap: 25px; border-bottom: 1px solid var(--line); }
.tab { position: relative; padding: 15px 0; color: var(--muted); background: none; border: 0; font-size: 11px; font-weight: 800; letter-spacing: .08em; text-transform: uppercase; }
.tab.active { color: var(--ink); }
.tab.active::after { content: ""; position: absolute; right: 0; bottom: -1px; left: 0; height: 2px; background: var(--red); }
.tab span { margin-left: 5px; padding: 2px 6px; color: white; background: var(--ink); border-radius: 10px; font-size: 9px; }
.tab-content { display: none; }
.tab-content.active { display: block; }
.form-section { margin-top: 25px; padding: 30px; display: grid; grid-template-columns: 55px minmax(190px, .35fr) minmax(0, 1fr); gap: 24px; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); }
.section-number { width: 42px; height: 42px; display: grid; place-items: center; color: var(--red); border: 1px solid var(--line); border-radius: 50%; font: 700 13px Georgia, serif; }
.section-heading h3 { margin: 8px 0 10px; font: 700 27px Georgia, serif; }
.section-heading p { max-width: 235px; margin: 0; color: var(--muted); font-size: 11px; line-height: 1.65; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 16px; }
.form-grid label, .visit-form label { display: flex; flex-direction: column; gap: 7px; }
.form-grid label > span, .visit-form label > span, fieldset legend { color: var(--muted); font-size: 9px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.wide { grid-column: 1 / -1; }
input, textarea {
  width: 100%;
  padding: 12px 13px;
  outline: none;
  color: var(--ink);
  background: #fbfaf6;
  border: 1px solid var(--line);
  border-radius: 9px;
  transition: .2s;
}
input { min-height: 44px; }
textarea { resize: vertical; line-height: 1.5; }
input:focus, textarea:focus { background: white; border-color: #817d73; box-shadow: 0 0 0 3px rgba(129,125,115,.1); }
fieldset { margin: 0; padding: 0; border: 0; }
fieldset legend { margin-bottom: 7px; }
.segmented { display: grid; grid-template-columns: repeat(3, 1fr); gap: 8px; }
.segmented label { display: block; }
.segmented input { position: absolute; opacity: 0; pointer-events: none; }
.segmented span { min-height: 44px; display: grid; place-items: center; background: #fbfaf6; border: 1px solid var(--line); border-radius: 9px; font-size: 11px; font-weight: 700; }
.segmented input:checked + span { color: white; background: var(--ink); border-color: var(--ink); }

.visit-entry { margin-top: 25px; padding: 30px; background: var(--ink); border-radius: var(--radius); color: white; }
.visit-entry-heading { display: flex; align-items: end; justify-content: space-between; gap: 30px; }
.visit-entry-heading p { max-width: 370px; margin: 0; color: #8e8b83; font-size: 11px; line-height: 1.65; }
.visit-form { margin-top: 25px; display: grid; grid-template-columns: repeat(3, minmax(0, 1fr)); gap: 15px; }
.visit-form input, .visit-form textarea { color: white; background: #1d1d1a; border-color: #3b3933; }
.visit-form input:focus, .visit-form textarea:focus { background: #23231f; border-color: #7d786f; box-shadow: none; }
.visit-form label > span { color: #908d84; }
.visit-submit { grid-column: 3; justify-self: end; width: 100%; }
.visit-history { margin-top: 15px; padding: 30px; background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); }
.timeline { margin-top: 25px; }
.timeline-empty { padding: 25px 0; color: var(--muted); font-size: 12px; }
.visit-card { position: relative; padding: 0 0 24px 35px; border-left: 1px solid var(--line); }
.visit-card::before { content: ""; position: absolute; left: -5px; top: 3px; width: 9px; height: 9px; background: var(--red); border: 3px solid var(--white); border-radius: 50%; box-shadow: 0 0 0 1px var(--red); }
.visit-card:last-child { padding-bottom: 0; border-left-color: transparent; }
.visit-card-header { display: flex; justify-content: space-between; gap: 15px; }
.visit-card h4 { margin: 0; font: 700 18px Georgia, serif; }
.visit-date { display: block; margin-bottom: 5px; color: var(--red); font-size: 9px; font-weight: 800; letter-spacing: .13em; text-transform: uppercase; }
.visit-delete { padding: 2px 0; color: #a09d94; background: none; border: 0; font-size: 10px; }
.visit-delete:hover { color: var(--red); }
.visit-details { margin-top: 14px; display: grid; grid-template-columns: repeat(3, 1fr); gap: 10px; }
.visit-detail { padding: 11px; background: var(--paper); border-radius: 8px; }
.visit-detail span { display: block; margin-bottom: 5px; color: var(--muted); font-size: 8px; font-weight: 800; letter-spacing: .1em; text-transform: uppercase; }
.visit-detail p { margin: 0; font-size: 11px; line-height: 1.5; white-space: pre-wrap; }

dialog { width: min(560px, calc(100vw - 30px)); padding: 34px; color: var(--ink); background: var(--white); border: 1px solid var(--line); border-radius: var(--radius); box-shadow: var(--shadow); }
dialog::backdrop { background: rgba(17,17,15,.67); backdrop-filter: blur(3px); }
dialog h2 { margin: 12px 0; font: 700 35px/1.05 Georgia, serif; }
dialog p { color: var(--muted); line-height: 1.65; }
dialog small { display: block; margin-top: 20px; color: var(--muted); line-height: 1.5; }
.dialog-close { position: absolute; top: 15px; right: 17px; color: var(--muted); background: none; border: 0; font-size: 25px; }
.dialog-actions { margin-top: 25px; display: grid; grid-template-columns: 1fr 1fr; gap: 8px; }
.file-label input { display: none; }
.toast-container { position: fixed; right: 20px; bottom: 20px; z-index: 100; display: grid; gap: 8px; }
.toast { min-width: 260px; padding: 13px 16px; color: white; background: var(--ink); border-left: 3px solid var(--red); border-radius: 8px; box-shadow: var(--shadow); font-size: 12px; animation: toast-in .25s ease both; }
@keyframes toast-in { from { opacity: 0; transform: translateY(8px); } }
.sidebar-backdrop { display: none; }

@media (max-width: 1060px) {
  .app-shell { grid-template-columns: 270px minmax(0, 1fr); }
  .sidebar { width: 270px; }
  .form-section { grid-template-columns: 42px 1fr; }
  .section-heading { grid-column: 2; }
  .form-grid { grid-column: 1 / -1; }
  .customer-header { grid-template-columns: 1fr; align-items: start; }
  .customer-actions { justify-content: flex-start; }
  .stat-card strong { font-size: 48px; }
}

@media (max-width: 820px) {
  .app-shell { display: block; }
  .sidebar { width: min(320px, 88vw); transform: translateX(-101%); transition: transform .25s ease; box-shadow: 15px 0 40px rgba(0,0,0,.25); }
  .sidebar.open { transform: translateX(0); }
  .sidebar-backdrop.open { position: fixed; inset: 0; z-index: 15; display: block; background: rgba(0,0,0,.45); }
  .main-content { min-width: 0; }
  .mobile-menu { display: block; }
  .topbar { min-height: 78px; padding: 14px 18px; justify-content: flex-start; }
  .topbar > div:nth-child(2) { flex: 1; }
  .topbar h1 { font-size: 15px; }
  .privacy-pill { display: none; }
  .dashboard, .customer-view { padding: 30px 18px 45px; }
  .dashboard-intro { grid-template-columns: 1fr; gap: 20px; }
  .dashboard-intro h2 { font-size: clamp(43px, 12vw, 70px); }
  .stat-grid { grid-template-columns: 1fr 1fr; }
  .stat-card:last-child { grid-column: 1 / -1; }
  .dashboard-grid { grid-template-columns: 1fr; }
  .visit-form { grid-template-columns: 1fr 1fr; }
  .visit-submit { grid-column: 2; }
}

@media (max-width: 560px) {
  .topbar-actions .button { display: none; }
  .stat-grid { grid-template-columns: 1fr; }
  .stat-card:last-child { grid-column: auto; }
  .customer-title { align-items: flex-start; }
  .avatar.large { width: 53px; height: 53px; font-size: 14px; }
  .customer-title h2 { font-size: 29px; white-space: normal; }
  .customer-actions { display: grid; grid-template-columns: 1fr 1fr; }
  .customer-actions .button-primary { grid-column: 1 / -1; grid-row: 1; }
  .tabs { gap: 18px; }
  .form-section, .visit-entry, .visit-history { padding: 20px; }
  .form-section { grid-template-columns: 1fr; gap: 13px; }
  .section-heading { grid-column: auto; }
  .form-grid { grid-column: auto; grid-template-columns: 1fr; }
  .wide { grid-column: auto; }
  .segmented { grid-template-columns: 1fr; }
  .visit-entry-heading { display: block; }
  .visit-entry-heading p { margin-top: 13px; }
  .visit-form { grid-template-columns: 1fr; }
  .visit-submit { grid-column: auto; }
  .visit-details { grid-template-columns: 1fr; }
  .dialog-actions { grid-template-columns: 1fr; }
}

@media print {
  body { background: white; }
  .sidebar, .topbar, .back-button, .customer-actions, .tabs, #visitsTab, .toast-container { display: none !important; }
  .app-shell, .main-content { display: block; }
  .customer-view { padding: 0; }
  .customer-header { display: block; margin-bottom: 20px; }
  .customer-title { border-bottom: 2px solid #111; padding-bottom: 20px; }
  .tab-content, #profileTab { display: block !important; }
  .form-section { break-inside: avoid; margin-top: 14px; padding: 18px; grid-template-columns: 40px 170px 1fr; box-shadow: none; }
  input, textarea, .segmented span { background: white; border-color: #aaa; }
}
