:root {
  color-scheme: light;
  --ink: #152528;
  --ink-soft: #5e6e70;
  --paper: #ffffff;
  --canvas: #f3f6f4;
  --line: #dce5e2;
  --line-strong: #c8d4d1;
  --primary: #0d5c63;
  --primary-dark: #08474c;
  --primary-soft: #e4f1ef;
  --accent: #d89b43;
  --danger: #b83c3c;
  --danger-soft: #fae8e7;
  --success: #287a57;
  --shadow-sm: 0 1px 2px rgba(18, 42, 43, 0.05);
  --shadow-md: 0 14px 35px rgba(18, 42, 43, 0.12);
  --radius: 16px;
  font-family: Inter, ui-sans-serif, system-ui, -apple-system, BlinkMacSystemFont, "Segoe UI", sans-serif;
}

* { box-sizing: border-box; }

html { min-height: 100%; background: var(--canvas); }

body {
  min-width: 320px;
  min-height: 100vh;
  margin: 0;
  color: var(--ink);
  background:
    radial-gradient(circle at 85% -10%, rgba(13, 92, 99, 0.09), transparent 35%),
    var(--canvas);
}

button, input, select, textarea { font: inherit; }
button { color: inherit; }
[hidden] { display: none !important; }

.eyebrow {
  margin: 0 0 8px;
  color: var(--primary);
  font-size: 0.72rem;
  font-weight: 800;
  letter-spacing: 0.13em;
  text-transform: uppercase;
}

.brand-mark {
  display: grid;
  width: 56px;
  height: 56px;
  place-items: center;
  border: 1px solid rgba(255,255,255,0.35);
  border-radius: 16px;
  color: white;
  background: rgba(255,255,255,0.1);
  font-weight: 900;
  letter-spacing: -0.05em;
}

.brand-mark-small {
  width: 42px;
  height: 42px;
  border: 0;
  border-radius: 12px;
  background: var(--primary);
  font-size: 0.86rem;
}

.login-shell {
  display: grid;
  min-height: 100vh;
  grid-template-columns: minmax(340px, 0.9fr) minmax(420px, 1.1fr);
}

.login-intro {
  display: flex;
  min-height: 100vh;
  padding: clamp(36px, 7vw, 96px);
  flex-direction: column;
  justify-content: center;
  color: white;
  background:
    linear-gradient(145deg, rgba(7, 58, 63, 0.96), rgba(13, 92, 99, 0.91)),
    repeating-linear-gradient(135deg, transparent 0 28px, rgba(255,255,255,0.06) 28px 29px);
}

.login-intro .eyebrow { margin-top: 64px; color: #a9d8d2; }
.login-intro h1 { max-width: 600px; margin: 0; font-size: clamp(2.5rem, 5vw, 5.4rem); line-height: 0.98; letter-spacing: -0.055em; }
.login-lead { max-width: 560px; margin: 28px 0 0; color: rgba(255,255,255,0.75); font-size: 1.08rem; line-height: 1.7; }

.feature-list { display: grid; max-width: 560px; margin: 60px 0 0; padding: 0; gap: 0; list-style: none; }
.feature-list li { display: flex; padding: 16px 0; align-items: center; gap: 18px; border-top: 1px solid rgba(255,255,255,0.16); color: rgba(255,255,255,0.86); }
.feature-list span { color: #a9d8d2; font-size: 0.72rem; font-weight: 800; letter-spacing: 0.12em; }

.login-panel { display: grid; padding: 32px; place-items: center; }
.login-card { width: min(100%, 430px); padding: clamp(28px, 5vw, 52px); border: 1px solid var(--line); border-radius: 24px; background: rgba(255,255,255,0.92); box-shadow: var(--shadow-md); }
.login-card h2 { margin: 0; font-size: 2rem; letter-spacing: -0.04em; }
.login-card > p:not(.eyebrow, .form-error, .privacy-note) { margin: 12px 0 30px; color: var(--ink-soft); line-height: 1.6; }
.mobile-brand { display: none; margin-bottom: 38px; align-items: center; gap: 10px; font-weight: 800; }
.mobile-brand span { display: grid; width: 38px; height: 38px; place-items: center; border-radius: 10px; color: white; background: var(--primary); font-size: 0.78rem; }
.privacy-note { margin: 20px 0 0; color: var(--ink-soft); font-size: 0.76rem; text-align: center; }

.field { display: grid; gap: 7px; }
.field > span { color: #3d5052; font-size: 0.79rem; font-weight: 750; }
.field input, .field select, .field textarea, .records-toolbar select, .search-field {
  width: 100%;
  border: 1px solid var(--line-strong);
  border-radius: 11px;
  color: var(--ink);
  background: var(--paper);
  outline: none;
  transition: border-color 0.18s ease, box-shadow 0.18s ease;
}
.field input, .field select, .records-toolbar select { min-height: 46px; padding: 0 13px; }
.field textarea { min-height: 76px; padding: 12px 13px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus, .records-toolbar select:focus, .search-field:focus-within { border-color: var(--primary); box-shadow: 0 0 0 3px rgba(13, 92, 99, 0.12); }

.button {
  display: inline-flex;
  min-height: 44px;
  padding: 0 18px;
  align-items: center;
  justify-content: center;
  gap: 9px;
  border: 1px solid transparent;
  border-radius: 11px;
  cursor: pointer;
  font-size: 0.86rem;
  font-weight: 780;
  text-decoration: none;
  transition: transform 0.15s ease, background 0.15s ease, border-color 0.15s ease;
}
.button:hover { transform: translateY(-1px); }
.button:disabled { cursor: wait; opacity: 0.6; transform: none; }
.button-primary { color: white; background: var(--primary); box-shadow: 0 6px 16px rgba(13,92,99,0.18); }
.button-primary:hover { background: var(--primary-dark); }
.button-secondary { border-color: var(--line-strong); background: var(--paper); }
.button-secondary:hover, .button-ghost:hover { border-color: #aebfbb; background: #f9fbfa; }
.button-ghost { border-color: transparent; background: transparent; }
.button-danger { color: var(--danger); border-color: #efc2c0; background: var(--danger-soft); }
.button-block { width: 100%; margin-top: 8px; }
.button-compact { min-height: 38px; padding: 0 13px; font-size: 0.78rem; }
.button-icon { font-size: 1.15rem; font-weight: 500; }
.form-error { min-height: 20px; margin: 12px 0; color: var(--danger); font-size: 0.82rem; font-weight: 650; }
.turnstile-box { margin: 16px 0; }

.app-shell { min-height: 100vh; }
.app-header { position: sticky; z-index: 20; top: 0; display: flex; min-height: 72px; padding: 0 clamp(18px, 4vw, 58px); align-items: center; justify-content: space-between; border-bottom: 1px solid rgba(200,212,209,0.8); background: rgba(255,255,255,0.88); backdrop-filter: blur(15px); }
.app-brand { display: flex; align-items: center; gap: 12px; color: var(--ink); text-decoration: none; }
.app-brand > span:last-child { display: grid; }
.app-brand strong { font-size: 0.92rem; }
.app-brand small { margin-top: 2px; color: var(--ink-soft); font-size: 0.66rem; }
.header-actions { display: flex; align-items: center; gap: 12px; }
.status-pill { display: inline-flex; padding: 7px 11px; align-items: center; gap: 7px; border-radius: 999px; color: var(--success); background: #e9f4ee; font-size: 0.72rem; font-weight: 750; }
.status-pill i { width: 7px; height: 7px; border-radius: 50%; background: var(--success); box-shadow: 0 0 0 3px rgba(40,122,87,0.12); }

.main-content { width: min(1380px, calc(100% - 36px)); margin: 0 auto; padding: 48px 0 80px; }
.page-heading { display: flex; align-items: flex-end; justify-content: space-between; gap: 28px; }
.page-heading h1 { margin: 0; font-size: clamp(2rem, 4vw, 3.5rem); letter-spacing: -0.055em; }
.page-heading p:last-child { margin: 10px 0 0; color: var(--ink-soft); }

.stats-grid { display: grid; margin-top: 34px; grid-template-columns: repeat(4, minmax(0, 1fr)); gap: 14px; }
.stat-card { display: flex; min-height: 108px; padding: 20px; align-items: center; gap: 15px; border: 1px solid var(--line); border-radius: var(--radius); background: rgba(255,255,255,0.82); box-shadow: var(--shadow-sm); }
.stat-icon { display: grid; width: 42px; height: 42px; flex: 0 0 auto; place-items: center; border-radius: 12px; color: var(--primary); background: var(--primary-soft); font-size: 0.78rem; font-weight: 900; }
.stat-card div { display: grid; }
.stat-card strong { font-size: 1.8rem; line-height: 1; letter-spacing: -0.04em; }
.stat-card div span { margin-top: 7px; color: var(--ink-soft); font-size: 0.76rem; }
.stat-primary { color: white; border-color: var(--primary); background: var(--primary); }
.stat-primary .stat-icon { color: white; background: rgba(255,255,255,0.14); }
.stat-primary div span { color: rgba(255,255,255,0.7); }
.stats-note { margin: 8px 0 0; color: var(--ink-soft); font-size: 0.68rem; text-align: right; }

.records-panel { margin-top: 28px; border: 1px solid var(--line); border-radius: 20px; background: rgba(255,255,255,0.9); box-shadow: var(--shadow-sm); overflow: hidden; }
.records-toolbar { display: grid; padding: 18px; grid-template-columns: minmax(250px, 1fr) 220px auto; gap: 10px; border-bottom: 1px solid var(--line); }
.search-field { display: flex; min-height: 46px; padding: 0 13px; align-items: center; gap: 10px; }
.search-field > span { color: var(--ink-soft); font-size: 1.25rem; }
.search-field input { width: 100%; border: 0; outline: 0; background: transparent; }
.records-toolbar select { min-height: 46px; padding: 0 12px; }
.records-title-row { display: flex; padding: 20px 22px 12px; align-items: center; justify-content: space-between; }
.records-title-row > div { display: flex; align-items: baseline; gap: 10px; }
.records-title-row h2 { margin: 0; font-size: 1.05rem; }
.records-title-row span { color: var(--ink-soft); font-size: 0.74rem; }
.icon-button { display: grid; width: 38px; height: 38px; padding: 0; place-items: center; border: 1px solid var(--line); border-radius: 10px; cursor: pointer; color: var(--ink-soft); background: white; font-size: 1.25rem; }
.icon-button:hover { color: var(--primary); border-color: var(--primary); }

.customer-list { display: grid; padding: 0 12px 12px; gap: 8px; }
.customer-row { display: grid; min-height: 82px; padding: 13px 14px; align-items: center; grid-template-columns: minmax(240px, 1.4fr) minmax(160px, 0.8fr) minmax(120px, 0.6fr) minmax(110px, 0.4fr) auto; gap: 16px; border: 1px solid transparent; border-radius: 13px; background: #fbfcfc; transition: border-color 0.16s ease, background 0.16s ease; }
.customer-row:hover { border-color: var(--line-strong); background: white; }
.customer-main { display: flex; min-width: 0; align-items: center; gap: 13px; }
.customer-avatar { display: grid; width: 42px; height: 42px; flex: 0 0 auto; place-items: center; border-radius: 12px; color: var(--primary); background: var(--primary-soft); font-weight: 850; }
.customer-main div, .customer-contact { min-width: 0; }
.customer-main strong, .customer-contact strong { display: block; overflow: hidden; font-size: 0.86rem; text-overflow: ellipsis; white-space: nowrap; }
.customer-main span, .customer-contact a, .customer-meta span { display: block; margin-top: 4px; overflow: hidden; color: var(--ink-soft); font-size: 0.73rem; text-decoration: none; text-overflow: ellipsis; white-space: nowrap; }
.customer-contact a:hover { color: var(--primary); }
.customer-meta strong { font-size: 0.84rem; }
.city-badge { display: inline-flex; width: fit-content; padding: 6px 9px; border-radius: 999px; color: #5d4a2d; background: #f5ead9; font-size: 0.71rem; font-weight: 750; }
.row-actions { display: flex; justify-content: flex-end; gap: 6px; }
.row-actions button { min-height: 36px; padding: 0 11px; }

.empty-state { padding: 70px 24px; text-align: center; }
.empty-icon { display: grid; width: 56px; height: 56px; margin: 0 auto 16px; place-items: center; border-radius: 16px; color: var(--primary); background: var(--primary-soft); font-size: 1.6rem; }
.empty-state h3 { margin: 0; }
.empty-state p { margin: 8px 0 20px; color: var(--ink-soft); }
.loading-row { padding: 54px; color: var(--ink-soft); text-align: center; }

.modal { width: min(920px, calc(100% - 28px)); max-height: calc(100vh - 32px); padding: 0; border: 0; border-radius: 20px; background: transparent; box-shadow: var(--shadow-md); }
.modal::backdrop { background: rgba(13, 27, 29, 0.56); backdrop-filter: blur(4px); }
.modal-card { display: flex; max-height: calc(100vh - 32px); flex-direction: column; border-radius: 20px; background: var(--paper); overflow: hidden; }
.modal-header { display: flex; padding: 22px 24px; align-items: flex-start; justify-content: space-between; border-bottom: 1px solid var(--line); }
.modal-header h2 { margin: 0; font-size: 1.45rem; letter-spacing: -0.035em; }
.modal-body { padding: 24px; overflow: auto; }
.modal-footer { display: flex; padding: 16px 24px; justify-content: flex-end; gap: 9px; border-top: 1px solid var(--line); background: #fafcfa; }
.form-section + .form-section { margin-top: 32px; padding-top: 28px; border-top: 1px solid var(--line); }
.section-heading, .section-heading-copy { display: flex; align-items: center; gap: 12px; }
.section-heading { margin-bottom: 18px; }
.section-heading-action { justify-content: space-between; }
.section-heading > span, .section-heading-copy > span { display: grid; width: 32px; height: 32px; flex: 0 0 auto; place-items: center; border-radius: 10px; color: var(--primary); background: var(--primary-soft); font-size: 0.76rem; font-weight: 850; }
.section-heading h3 { margin: 0; font-size: 0.96rem; }
.section-heading p { margin: 3px 0 0; color: var(--ink-soft); font-size: 0.73rem; }
.form-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 15px; }
.field-span-2 { grid-column: 1 / -1; }
.device-form-list { display: grid; gap: 12px; }
.device-form-card { padding: 16px; border: 1px solid var(--line); border-radius: 14px; background: #fafcfa; }
.device-form-header { display: flex; margin-bottom: 14px; align-items: center; justify-content: space-between; }
.device-form-header > div { display: flex; align-items: center; gap: 8px; }
.device-number { display: grid; width: 25px; height: 25px; place-items: center; border-radius: 8px; color: white; background: var(--primary); font-size: 0.7rem; font-weight: 800; }
.remove-device-button { border: 0; cursor: pointer; color: var(--danger); background: transparent; font-size: 0.73rem; font-weight: 750; }
.remove-device-button:disabled { cursor: not-allowed; opacity: 0.35; }
.form-grid-device { grid-template-columns: 0.8fr 1fr 1fr 1fr; }

.detail-summary { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.detail-card { padding: 18px; border: 1px solid var(--line); border-radius: 14px; background: #fafcfa; }
.detail-card h3 { margin: 0 0 14px; font-size: 0.9rem; }
.detail-list { display: grid; margin: 0; grid-template-columns: auto 1fr; gap: 9px 14px; font-size: 0.8rem; }
.detail-list dt { color: var(--ink-soft); }
.detail-list dd { margin: 0; font-weight: 650; overflow-wrap: anywhere; }
.detail-section { margin-top: 26px; }
.detail-section-heading { display: flex; margin-bottom: 12px; align-items: center; justify-content: space-between; }
.detail-section-heading h3 { margin: 0; font-size: 0.98rem; }
.detail-section-heading span { color: var(--ink-soft); font-size: 0.72rem; }
.device-list { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 10px; }
.device-card { padding: 15px; border: 1px solid var(--line); border-radius: 13px; }
.device-card header { display: flex; align-items: center; justify-content: space-between; gap: 8px; }
.device-card strong { font-size: 0.86rem; }
.device-card .serial { display: inline-flex; margin-top: 9px; padding: 5px 8px; border-radius: 7px; color: var(--primary); background: var(--primary-soft); font-family: ui-monospace, SFMono-Regular, Consolas, monospace; font-size: 0.72rem; }
.device-card p { margin: 9px 0 0; color: var(--ink-soft); font-size: 0.74rem; }
.service-form { display: grid; padding: 16px; grid-template-columns: 150px 1fr 180px; gap: 12px; border: 1px solid var(--line); border-radius: 14px; background: #fafcfa; }
.service-form .field-span-all { grid-column: 1 / -1; }
.service-form-actions { display: flex; grid-column: 1 / -1; justify-content: flex-end; }
.service-list { display: grid; margin-top: 12px; gap: 9px; }
.service-item { display: grid; padding: 14px 15px; grid-template-columns: 110px 1fr auto; gap: 14px; border: 1px solid var(--line); border-radius: 13px; }
.service-date { color: var(--ink-soft); font-size: 0.76rem; font-weight: 700; }
.service-item h4 { margin: 0; font-size: 0.85rem; }
.service-item p { margin: 6px 0 0; color: var(--ink-soft); font-size: 0.76rem; line-height: 1.5; white-space: pre-wrap; }
.service-device { display: block; margin-top: 6px; color: var(--primary); font-size: 0.7rem; }
.status-badge { display: inline-flex; height: fit-content; padding: 5px 8px; border-radius: 999px; color: var(--success); background: #e8f3ed; font-size: 0.67rem; font-weight: 750; }
.status-badge.waiting { color: #8b5b17; background: #f8ecd8; }
.status-badge.follow { color: var(--danger); background: var(--danger-soft); }
.service-actions { display: flex; align-items: flex-start; gap: 7px; }
.link-button { padding: 0; border: 0; cursor: pointer; color: var(--danger); background: transparent; font-size: 0.7rem; font-weight: 700; }
.detail-actions { display: flex; margin-top: 22px; justify-content: flex-end; gap: 8px; }
.muted-message { padding: 24px; border: 1px dashed var(--line-strong); border-radius: 13px; color: var(--ink-soft); font-size: 0.8rem; text-align: center; }

.toast-container { position: fixed; z-index: 100; right: 20px; bottom: 20px; display: grid; width: min(360px, calc(100% - 40px)); gap: 9px; }
.toast { padding: 13px 15px; border: 1px solid var(--line); border-left: 4px solid var(--success); border-radius: 11px; background: white; box-shadow: var(--shadow-md); font-size: 0.82rem; animation: toast-in 0.22s ease both; }
.toast.error { border-left-color: var(--danger); }
@keyframes toast-in { from { opacity: 0; transform: translateY(10px); } }

@media (max-width: 1050px) {
  .stats-grid { grid-template-columns: repeat(2, minmax(0, 1fr)); }
  .customer-row { grid-template-columns: minmax(220px, 1.2fr) minmax(150px, 0.8fr) 100px auto; }
  .customer-row .customer-meta { display: none; }
  .form-grid-device { grid-template-columns: repeat(2, minmax(0, 1fr)); }
}

@media (max-width: 760px) {
  .login-shell { display: block; }
  .login-intro { display: none; }
  .login-panel { min-height: 100vh; padding: 20px; }
  .mobile-brand { display: flex; }
  .login-card { padding: 28px 24px; }
  .app-header { min-height: 64px; padding: 0 14px; }
  .app-brand small, .status-pill { display: none; }
  .main-content { width: min(100% - 24px, 1380px); padding: 30px 0 64px; }
  .page-heading { align-items: flex-start; flex-direction: column; }
  .page-heading .button { width: 100%; }
  .stats-grid { margin-top: 24px; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 9px; }
  .stat-card { min-height: 92px; padding: 14px; }
  .stat-card strong { font-size: 1.5rem; }
  .records-toolbar { grid-template-columns: 1fr 1fr; }
  .search-field { grid-column: 1 / -1; }
  .records-toolbar .button { padding: 0 10px; }
  .customer-row { padding: 14px; grid-template-columns: 1fr auto; gap: 12px; }
  .customer-contact, .customer-row > .city-badge { display: none; }
  .row-actions { align-self: center; }
  .row-actions .button-secondary { display: none; }
  .modal { width: 100%; max-height: 100vh; margin: 0; border-radius: 0; }
  .modal-card { min-height: 100vh; max-height: 100vh; border-radius: 0; }
  .modal-header, .modal-body, .modal-footer { padding-left: 17px; padding-right: 17px; }
  .form-grid, .form-grid-device, .detail-summary, .device-list { grid-template-columns: 1fr; }
  .field-span-2 { grid-column: auto; }
  .section-heading-action { align-items: flex-start; gap: 14px; }
  .section-heading-action { flex-direction: column; }
  .section-heading-action .button { width: 100%; }
  .service-form { grid-template-columns: 1fr; }
  .service-form .field-span-all, .service-form-actions { grid-column: auto; }
  .service-form-actions .button { width: 100%; }
  .service-item { grid-template-columns: 1fr auto; }
  .service-item > div:nth-child(2) { grid-column: 1 / -1; grid-row: 2; }
}

@media (max-width: 430px) {
  .stats-grid { grid-template-columns: 1fr 1fr; }
  .stat-icon { width: 36px; height: 36px; }
  .stat-card { gap: 10px; }
  .stat-card div span { font-size: 0.68rem; }
  .records-toolbar { grid-template-columns: 1fr; }
  .search-field { grid-column: auto; }
  .records-title-row { padding-inline: 16px; }
}
