/* ============================================================
   Али-Дент Family Dental Center — clinical UI
   Vanilla CSS, responsive (phone + desktop), print support.
   ============================================================ */

:root {
  --brand: #0e7c86;
  --brand-dark: #0a5c64;
  --brand-light: #e6f4f5;
  --accent: #f4a12c;
  --ink: #1f2a33;
  --muted: #64748b;
  --line: #dbe3ea;
  --bg: #f4f7f9;
  --card: #ffffff;
  --danger: #d64545;
  --ok: #1f9d55;
  --warn: #b7791f;
  --radius: 10px;
  --shadow: 0 1px 4px rgba(15, 40, 50, 0.08);
  --font: "Segoe UI", system-ui, -apple-system, Roboto, "Helvetica Neue", Arial, sans-serif;
}

* { box-sizing: border-box; }

html, body { margin: 0; padding: 0; }

body {
  font-family: var(--font);
  background: var(--bg);
  color: var(--ink);
  font-size: 15px;
  line-height: 1.45;
}

/* ---------- Login ---------- */
#login-view {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 24px;
  background: linear-gradient(135deg, var(--brand-dark), var(--brand));
}

.login-card {
  background: var(--card);
  border-radius: 14px;
  box-shadow: 0 8px 30px rgba(0, 0, 0, 0.25);
  padding: 32px 32px 28px;
  width: 100%;
  max-width: 400px;
  text-align: center;
}

.login-card .logo img {
  height: 72px;
  max-width: 220px;
  object-fit: contain;
}

.login-card h1 { margin: 12px 0 4px; font-size: 22px; }
.login-card .clinic-sub { color: var(--muted); margin: 0 0 20px; font-size: 14px; }

.login-card form { text-align: left; }
.login-lang {
  display: flex;
  justify-content: center;
  gap: 6px;
  margin-bottom: 18px;
}

/* ---------- App shell ---------- */
#app { display: flex; flex-direction: column; min-height: 100vh; }
#app[hidden] { display: none; }

#app-header {
  background: var(--brand-dark);
  color: #fff;
  display: flex;
  align-items: center;
  gap: 14px;
  padding: 8px 18px;
  position: sticky;
  top: 0;
  z-index: 50;
  flex-wrap: wrap;
}

#app-header .logo img { height: 42px; max-width: 140px; object-fit: contain; background: #fff; border-radius: 6px; padding: 3px; }
#app-header .clinic-name { font-size: 19px; font-weight: 700; letter-spacing: 0.3px; }

.header-spacer { flex: 1; }

.header-group { display: flex; align-items: center; gap: 8px; font-size: 13px; }
.header-group label { opacity: 0.85; }
.header-group select {
  background: rgba(255, 255, 255, 0.12);
  color: #fff;
  border: 1px solid rgba(255, 255, 255, 0.35);
  border-radius: 6px;
  padding: 5px 8px;
  font-size: 13px;
}
.header-group select option { color: #111; }

.seg { display: inline-flex; border: 1px solid rgba(255,255,255,0.35); border-radius: 6px; overflow: hidden; }
.seg button {
  background: transparent; color: #fff; border: 0; padding: 5px 10px;
  font-size: 13px; cursor: pointer;
}
.seg button.active { background: #fff; color: var(--brand-dark); font-weight: 700; }

.btn-logout {
  background: rgba(255,255,255,0.14); color: #fff; border: 1px solid rgba(255,255,255,0.4);
  border-radius: 6px; padding: 5px 12px; cursor: pointer; font-size: 13px;
}
.btn-logout:hover { background: rgba(255,255,255,0.28); }

#app-body { display: flex; flex: 1; min-height: 0; }

#app-nav {
  width: 208px;
  background: var(--card);
  border-right: 1px solid var(--line);
  padding: 14px 10px;
  display: flex;
  flex-direction: column;
  gap: 2px;
  flex-shrink: 0;
}

#app-nav a {
  display: block;
  padding: 10px 14px;
  border-radius: 8px;
  color: var(--ink);
  text-decoration: none;
  font-size: 15px;
  cursor: pointer;
}
#app-nav a:hover { background: var(--brand-light); }
#app-nav a.active { background: var(--brand); color: #fff; font-weight: 600; }

#app-main {
  flex: 1;
  padding: 22px 26px;
  max-width: 1200px;
  width: 100%;
  margin: 0 auto;
  min-width: 0;
}

/* ---------- Cards, tables, forms ---------- */
.card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  box-shadow: var(--shadow);
  padding: 18px 20px;
  margin-bottom: 18px;
}

.card h2, .card h3 { margin: 0 0 12px; }
.card h2 { font-size: 20px; }

.toolbar {
  display: flex;
  align-items: center;
  gap: 10px;
  margin-bottom: 14px;
  flex-wrap: wrap;
}
.toolbar .spacer { flex: 1; }

table.grid {
  width: 100%;
  border-collapse: collapse;
  font-size: 14px;
}
table.grid th, table.grid td {
  text-align: left;
  padding: 9px 10px;
  border-bottom: 1px solid var(--line);
  vertical-align: top;
}
table.grid th {
  background: #f1f5f8;
  font-weight: 600;
  white-space: nowrap;
}
table.grid tr:hover td { background: #fafcfd; }

.field { margin-bottom: 12px; }
.field label { display: block; font-weight: 600; font-size: 13px; margin-bottom: 4px; }
.field input[type="text"], .field input[type="email"], .field input[type="password"],
.field input[type="number"], .field input[type="date"], .field input[type="datetime-local"],
.field select, .field textarea {
  width: 100%;
  padding: 9px 10px;
  border: 1px solid var(--line);
  border-radius: 7px;
  font-size: 14px;
  font-family: inherit;
  background: #fff;
}
.field textarea { min-height: 80px; resize: vertical; }
.field input:focus, .field select:focus, .field textarea:focus {
  outline: 2px solid var(--brand);
  outline-offset: -1px;
  border-color: var(--brand);
}
.field .hint { font-size: 12px; color: var(--muted); margin-top: 3px; }

.form-row { display: flex; gap: 12px; flex-wrap: wrap; }
.form-row .field { flex: 1; min-width: 160px; }

/* ---------- Buttons ---------- */
.btn {
  display: inline-block;
  background: var(--brand);
  color: #fff;
  border: 0;
  border-radius: 7px;
  padding: 9px 18px;
  font-size: 14px;
  font-weight: 600;
  cursor: pointer;
}
.btn:hover { background: var(--brand-dark); }
.btn:disabled { opacity: 0.5; cursor: default; }

.btn-secondary {
  background: #e8eef2; color: var(--ink);
}
.btn-secondary:hover { background: #d7e1e8; }

.btn-danger { background: var(--danger); }
.btn-danger:hover { background: #b03636; }

.btn-small { padding: 5px 12px; font-size: 13px; }

.link-btn {
  background: none; border: 0; color: var(--brand);
  cursor: pointer; font-size: 14px; padding: 2px 4px; text-decoration: underline;
}
.link-btn.danger { color: var(--danger); }

/* ---------- Badges / statuses ---------- */
.badge {
  display: inline-block;
  font-size: 12px;
  font-weight: 600;
  padding: 2px 9px;
  border-radius: 20px;
  white-space: nowrap;
}
.badge.paid, .badge.done { background: #dcf5e5; color: #14703c; }
.badge.unpaid, .badge.scheduled { background: #fff3d6; color: #8a5a00; }
.badge.cancelled { background: #f6dada; color: #a02a2a; }
.badge.info { background: var(--brand-light); color: var(--brand-dark); }
.badge.archived { background: #e5e9ee; color: var(--muted); }

.money { font-variant-numeric: tabular-nums; white-space: nowrap; }
.total-row td { font-weight: 700; background: #f1f5f8; }

/* ---------- Calendar ---------- */
.week-bar { display: flex; align-items: center; gap: 10px; margin-bottom: 12px; flex-wrap: wrap; }
.week-grid { display: grid; grid-template-columns: repeat(7, 1fr); gap: 8px; }
.day-col {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 10px;
  cursor: pointer;
  min-height: 120px;
}
.day-col:hover { border-color: var(--brand); }
.day-col.selected { border: 2px solid var(--brand); background: var(--brand-light); }
.day-col.today { box-shadow: inset 0 0 0 2px var(--accent); }
.day-col .dow { font-size: 12px; color: var(--muted); text-transform: uppercase; }
.day-col .dnum { font-size: 20px; font-weight: 700; }
.day-col .count { font-size: 13px; margin-top: 6px; }

.appt-item {
  border: 1px solid var(--line);
  border-left: 4px solid var(--brand);
  border-radius: 7px;
  padding: 10px 12px;
  margin-bottom: 8px;
  background: #fff;
  display: flex;
  gap: 10px;
  align-items: center;
  flex-wrap: wrap;
}
.appt-item .time { font-weight: 700; min-width: 110px; }
.appt-item .grow { flex: 1; min-width: 140px; }
.appt-item.cancelled { opacity: 0.55; border-left-color: var(--danger); }

/* ---------- Dental chart ---------- */
.chart-toggle { display: flex; gap: 6px; margin-bottom: 10px; }
.chart-grid {
  display: grid;
  grid-template-columns: repeat(8, 1fr);
  gap: 6px;
  max-width: 560px;
}
.tooth {
  aspect-ratio: 1 / 1;
  border: 2px solid var(--line);
  border-radius: 8px;
  background: #fff;
  font-size: 13px;
  font-weight: 600;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 0;
}
.tooth:hover { border-color: var(--brand); }
.tooth.selected { background: var(--brand); border-color: var(--brand-dark); color: #fff; }

/* ---------- Treatment rows ---------- */
.proc-row, .inv-row {
  border: 1px solid var(--line);
  border-radius: 8px;
  padding: 12px;
  margin-bottom: 10px;
  background: #fbfdfd;
}
.proc-row-head { display: flex; align-items: center; gap: 10px; margin-bottom: 8px; }
.proc-row-head .num { font-weight: 700; color: var(--brand-dark); }
.tooth-pick {
  border: 2px dashed var(--brand);
  color: var(--brand-dark);
  background: #fff;
  border-radius: 7px;
  padding: 6px 14px;
  font-weight: 700;
  cursor: pointer;
  min-width: 64px;
}

/* ---------- Modal ---------- */
#modal-root:empty { display: none; }
.modal-backdrop {
  position: fixed; inset: 0;
  background: rgba(15, 30, 40, 0.5);
  display: flex; align-items: center; justify-content: center;
  z-index: 200;
  padding: 16px;
}
.modal {
  background: #fff;
  border-radius: 12px;
  max-width: 640px;
  width: 100%;
  max-height: 92vh;
  overflow-y: auto;
  padding: 22px 24px;
}
.modal.wide { max-width: 860px; }
.modal h2 { margin: 0 0 14px; font-size: 19px; }
.modal-actions { display: flex; justify-content: flex-end; gap: 10px; margin-top: 16px; }

/* ---------- Alerts ---------- */
.alert {
  padding: 10px 14px;
  border-radius: 8px;
  margin-bottom: 14px;
  font-size: 14px;
}
.alert-error { background: #fbe3e3; color: #a02a2a; border: 1px solid #f0b6b6; }
.alert-ok { background: #dcf5e5; color: #14703c; border: 1px solid #a9e3c2; }

.empty { color: var(--muted); padding: 18px; text-align: center; }

/* ---------- P&L summary cards ---------- */
.summary-cards { display: grid; grid-template-columns: repeat(auto-fit, minmax(150px, 1fr)); gap: 10px; margin-bottom: 16px; }
.summary-card {
  background: var(--card);
  border: 1px solid var(--line);
  border-radius: var(--radius);
  padding: 12px 14px;
}
.summary-card .label { font-size: 12px; color: var(--muted); text-transform: uppercase; }
.summary-card .value { font-size: 20px; font-weight: 700; margin-top: 4px; }
.summary-card .value.pos { color: var(--ok); }
.summary-card .value.neg { color: var(--danger); }

.tabs { display: flex; gap: 6px; margin-bottom: 14px; flex-wrap: wrap; }
.tabs button {
  border: 1px solid var(--line);
  background: #fff;
  border-radius: 20px;
  padding: 7px 16px;
  cursor: pointer;
  font-size: 14px;
}
.tabs button.active { background: var(--brand); border-color: var(--brand); color: #fff; font-weight: 600; }

.detail-grid { display: grid; grid-template-columns: 160px 1fr; gap: 6px 12px; font-size: 14px; margin-bottom: 14px; }
.detail-grid dt { color: var(--muted); }
.detail-grid dd { margin: 0; }

.attach-list { list-style: none; padding: 0; margin: 8px 0; }
.attach-list li {
  display: flex; align-items: center; gap: 10px;
  padding: 7px 0; border-bottom: 1px dashed var(--line);
  font-size: 14px;
}

.history-day { border: 1px solid var(--line); border-radius: var(--radius); padding: 14px 16px; margin-bottom: 12px; background: #fff; }
.history-day h3 { margin: 0 0 8px; font-size: 16px; display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.history-day ul { margin: 6px 0; padding-left: 20px; }

/* ---------- Print area ---------- */
#print-area { display: none; }

.print-doc {
  font-family: var(--font);
  color: #111;
  max-width: 700px;
  margin: 0 auto;
  padding: 10px;
}
.print-doc .p-head { display: flex; align-items: center; gap: 16px; border-bottom: 3px solid var(--brand); padding-bottom: 12px; margin-bottom: 16px; }
.print-doc .p-head img { height: 64px; max-width: 160px; object-fit: contain; }
.print-doc .p-head h1 { margin: 0; font-size: 22px; }
.print-doc .p-head .sub { font-size: 13px; color: #444; }
.print-doc table { width: 100%; border-collapse: collapse; font-size: 14px; margin: 12px 0; }
.print-doc table th, .print-doc table td { border: 1px solid #999; padding: 7px 9px; text-align: left; }
.print-doc table th { background: #eee; }
.print-doc .p-total { text-align: right; font-size: 17px; font-weight: 700; margin-top: 8px; }
.print-doc .p-section { margin-top: 18px; }
.print-doc .p-section h3 { margin: 0 0 6px; font-size: 15px; border-bottom: 1px solid #999; padding-bottom: 4px; }

/* ---------- Responsive ---------- */
@media (max-width: 860px) {
  #app-body { flex-direction: column; }
  #app-nav {
    width: 100%;
    flex-direction: row;
    overflow-x: auto;
    border-right: 0;
    border-bottom: 1px solid var(--line);
    padding: 8px;
  }
  #app-nav a { white-space: nowrap; padding: 8px 12px; font-size: 14px; }
  #app-main { padding: 14px; }
  .week-grid { grid-template-columns: repeat(7, minmax(88px, 1fr)); overflow-x: auto; }
  .day-col { min-height: 96px; }
  #app-header { padding: 8px 10px; gap: 8px; }
  #app-header .clinic-name { font-size: 16px; }
  .chart-grid { grid-template-columns: repeat(8, 1fr); }
  table.grid { font-size: 13px; }
  table.grid th, table.grid td { padding: 7px 6px; }
}

/* ---------- Print ---------- */
@media print {
  #app, #login-view, #modal-root, .no-print { display: none !important; }
  #print-area { display: block !important; }
  body { background: #fff; font-size: 13px; }
}
