:root {
  --primary: #2563eb;
  --primary-light: #dbeafe;
  --primary-dark: #1d4ed8;
  --success: #16a34a;
  --success-light: #dcfce7;
  --danger: #dc2626;
  --danger-light: #fef2f2;
  --warning: #f59e0b;
  --warning-light: #fef9c3;
  --purple: #7c3aed;
  --purple-light: #ede9fe;
  --bg: #f8fafc;
  --card: #ffffff;
  --border: #e2e8f0;
  --text: #1e293b;
  --text-muted: #64748b;
  --text-light: #94a3b8;
  --shadow: 0 1px 3px rgba(0,0,0,0.08);
  --shadow-lg: 0 4px 12px rgba(0,0,0,0.1);
  --radius: 8px;
  --radius-sm: 4px;
}
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body {
  height: 100%;
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', 'Hiragino Sans', 'Noto Sans JP', sans-serif;
  font-size: 13px;
  color: var(--text);
  background: var(--bg);
}

/* ===== Screen switching ===== */
.screen { display: none; height: 100vh; flex-direction: column; overflow: hidden; }
.screen.active { display: flex; }
#screenKarte { min-height: 100vh; height: auto; overflow: auto; }

/* ===== Common Header ===== */
.header {
  height: 48px;
  background: linear-gradient(135deg, var(--primary), var(--primary-dark));
  color: #fff;
  display: flex;
  align-items: center;
  padding: 0 16px;
  gap: 10px;
  box-shadow: 0 2px 6px rgba(37,99,235,0.3);
  z-index: 100;
  flex-shrink: 0;
}
.header .logo { font-size: 16px; font-weight: 700; letter-spacing: 1px; white-space: nowrap; }
.header .spacer { flex: 1; }
.header .clock { font-size: 15px; font-weight: 600; font-variant-numeric: tabular-nums; }

/* ======================================================
   SCREEN 1: Patient List
   ====================================================== */
.list-toolbar {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 20px;
  background: var(--card);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.list-toolbar .date-nav { display: flex; align-items: center; gap: 6px; }
.list-toolbar .date-nav button {
  background: var(--bg); border: 1px solid var(--border);
  width: 32px; height: 32px; border-radius: var(--radius-sm);
  font-size: 16px; cursor: pointer; display: flex; align-items: center; justify-content: center;
}
.list-toolbar .date-nav button:hover { background: var(--primary-light); }
.list-toolbar .date-input {
  font-size: 15px; font-weight: 700; border: 1px solid var(--border);
  border-radius: var(--radius-sm); padding: 5px 10px; font-family: inherit; cursor: pointer;
}
.list-toolbar .date-input:focus { outline: none; border-color: var(--primary); }
.list-stats { display: flex; gap: 16px; font-size: 13px; }
.list-stats .stat { display: flex; align-items: center; gap: 4px; }
.list-stats .stat-dot { width: 10px; height: 10px; border-radius: 50%; }
.list-stats .stat-num { font-weight: 700; font-size: 16px; }
.new-patient-btn {
  background: var(--success); color: #fff; border: none;
  padding: 8px 16px; border-radius: var(--radius-sm);
  font-size: 13px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.new-patient-btn:hover { background: #15803d; }

.list-container { flex: 1; overflow-y: auto; padding: 12px 20px; }
.patient-table {
  width: 100%; border-collapse: collapse; background: var(--card);
  border-radius: var(--radius); overflow: hidden; box-shadow: var(--shadow);
}
.patient-table thead th {
  background: var(--bg); padding: 10px 12px; text-align: left;
  font-size: 11px; font-weight: 700; color: var(--text-muted);
  text-transform: uppercase; letter-spacing: 0.5px;
  border-bottom: 2px solid var(--border); white-space: nowrap;
}
.patient-table tbody tr { border-bottom: 1px solid var(--border); cursor: pointer; transition: background 0.1s; }
.patient-table tbody tr:hover { background: var(--primary-light); }
.patient-table tbody tr.status-done-row { opacity: 0.6; }
.patient-table tbody td { padding: 10px 12px; font-size: 13px; vertical-align: middle; }
.patient-table .td-status { width: 70px; text-align: center; }
.patient-table .status-badge { display: inline-block; padding: 3px 10px; border-radius: 12px; font-size: 11px; font-weight: 600; }
.status-badge.waiting { background: var(--bg); color: var(--text-muted); border: 1px solid var(--border); }
.status-badge.active { background: var(--success-light); color: var(--success); border: 1px solid var(--success); }
.status-badge.done { background: var(--primary-light); color: var(--primary); }
.patient-table .td-name { font-weight: 600; }
.patient-table .td-name .sub { font-size: 11px; color: var(--text-muted); font-weight: 400; }
.patient-table .td-allergy { color: var(--danger); font-size: 11px; font-weight: 600; }
.patient-table .td-lane { text-align: center; font-weight: 700; font-size: 14px; }
.patient-table .td-questionnaire .q-badge { display: inline-block; padding: 2px 8px; border-radius: 8px; font-size: 10px; font-weight: 600; }
.q-badge.received { background: var(--success-light); color: var(--success); }
.q-badge.none { background: var(--bg); color: var(--text-light); }
.patient-table .td-actions { display: flex; gap: 4px; }
.td-actions .action-btn { padding: 5px 12px; border: none; border-radius: var(--radius-sm); font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit; }
.action-btn.karte-btn { background: var(--primary); color: #fff; }
.action-btn.karte-btn:hover { background: var(--primary-dark); }
.action-btn.call-btn { background: var(--success); color: #fff; }
.action-btn.call-btn:hover { background: #15803d; }

/* ======================================================
   SCREEN 2: Karte Dashboard
   ====================================================== */
.header-karte .back-btn {
  background: rgba(255,255,255,0.15); border: 1px solid rgba(255,255,255,0.3);
  color: #fff; padding: 5px 12px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.header-karte .back-btn:hover { background: rgba(255,255,255,0.25); }
.header-karte select {
  background: rgba(255,255,255,0.15); color: #fff; border: 1px solid rgba(255,255,255,0.3);
  padding: 4px 8px; border-radius: var(--radius-sm); font-size: 13px; cursor: pointer;
}
.header-karte select option { color: #333; background: #fff; }
.header-karte .patient-name { font-size: 18px; font-weight: 700; letter-spacing: 1px; }
.header-karte .patient-kana { font-size: 11px; opacity: 0.7; margin-left: -4px; }
.header-karte .patient-meta { font-size: 12px; opacity: 0.9; display: flex; gap: 6px; align-items: center; }
.header-karte .patient-meta span { background: rgba(255,255,255,0.2); padding: 2px 8px; border-radius: 10px; }
.header-karte .insurance-badge { background: var(--warning) !important; color: #000 !important; font-weight: 600; }
.exam-start-btn {
  background: var(--success); color: #fff; border: none;
  padding: 5px 12px; border-radius: var(--radius-sm);
  font-size: 12px; font-weight: 600; cursor: pointer; white-space: nowrap;
}
.exam-start-btn:hover { background: #15803d; }
.exam-start-btn.active { background: var(--danger); }
.time-surcharge-badge {
  background: var(--danger) !important; color: #fff !important;
  font-weight: 700; font-size: 11px; display: none;
}
.time-surcharge-badge.show { display: inline-block; }

/* ===== Visit Info Bar ===== */
.visit-info-bar {
  display: flex; align-items: center; gap: 20px;
  padding: 6px 16px; background: var(--card);
  border-bottom: 1px solid var(--border); flex-shrink: 0;
}
.visit-info-item { display: flex; align-items: center; gap: 6px; font-size: 12px; }
.visit-info-label { color: var(--text-muted); font-size: 11px; font-weight: 600; }
.visit-info-value { font-weight: 600; color: var(--text); }
.visit-info-select {
  border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 2px 6px; font-size: 12px; font-family: inherit; cursor: pointer; background: var(--card);
}
.visit-info-select:focus { outline: none; border-color: var(--primary); }

/* ===== Main Grid (v0.3 restructured: 3 columns) ===== */
.main-grid {
  display: grid;
  grid-template-columns: 220px 6px 1fr 6px 260px;
  grid-template-rows: 1fr;
  flex: 1;
  gap: 0;
  background: var(--border);
  min-height: 0;
}

/* Column resize handles */
.col-resize-handle {
  width: 6px;
  cursor: col-resize;
  background: var(--border);
  position: relative;
  z-index: 2;
  transition: background 0.15s;
}
.col-resize-handle:hover,
.col-resize-handle.active {
  background: var(--primary);
}
.col-resize-handle::after {
  content: '';
  position: absolute;
  top: 50%;
  left: 1px;
  width: 4px;
  height: 32px;
  transform: translateY(-50%);
  border-left: 1px solid rgba(255,255,255,0.5);
  border-right: 1px solid rgba(255,255,255,0.5);
}

/* Karte split resize handle */
.split-resize-handle {
  width: 6px;
  cursor: col-resize;
  background: var(--border);
  position: relative;
  z-index: 2;
  transition: background 0.15s;
}
.split-resize-handle:hover,
.split-resize-handle.active {
  background: var(--primary);
}

/* Richtext editor bottom resize */
.richtext-editor {
  resize: vertical;
}

/* Prevent text selection during resize */
body.resizing {
  cursor: col-resize !important;
  user-select: none !important;
  -webkit-user-select: none !important;
}
body.resizing * {
  cursor: col-resize !important;
}
body.resizing iframe,
body.resizing img {
  pointer-events: none;
}

/* ===== Panel Base ===== */
.panel { background: var(--card); display: flex; flex-direction: column; overflow: hidden; }
.panel-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  padding: 6px 10px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px; flex-shrink: 0; color: var(--text-muted);
}
.panel-title .icon { font-size: 14px; }
.panel-title .panel-actions { margin-left: auto; display: flex; gap: 4px; }
.panel-title .panel-action-btn {
  background: var(--bg); border: 1px solid var(--border);
  padding: 2px 6px; border-radius: var(--radius-sm); font-size: 10px;
  cursor: pointer; color: var(--text-muted);
}
.panel-title .panel-action-btn:hover { background: var(--primary-light); color: var(--primary); }
.panel-body { flex: 1; overflow-y: auto; padding: 8px 10px; }
.panel-body::-webkit-scrollbar { width: 4px; }
.panel-body::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ===== Left: Patient Info Tabs (Phase 3) ===== */
.patient-info { grid-row: 1; grid-column: 1; }
.patient-tabs-row {
  display: flex; gap: 1px; padding: 2px 4px; background: var(--bg);
  flex-shrink: 0; flex-wrap: wrap;
}
.patient-tab {
  flex: 1; padding: 3px 2px; text-align: center;
  font-size: 9px; font-weight: 600; cursor: pointer;
  background: var(--card); border: 1px solid var(--border);
  border-radius: var(--radius-sm) var(--radius-sm) 0 0;
  color: var(--text-muted); min-width: 0; white-space: nowrap;
}
.patient-tab.active {
  background: var(--primary); color: #fff; border-color: var(--primary);
}
.patient-tab:hover:not(.active) { background: var(--primary-light); }

.info-section { margin-bottom: 8px; }
.info-section-title {
  font-size: 11px; font-weight: 700; color: var(--primary);
  margin-bottom: 3px; padding-bottom: 2px;
  border-bottom: 1px solid var(--primary-light);
  display: flex; justify-content: space-between; align-items: center;
}
.info-section-title .edit-btn {
  font-size: 10px; color: var(--primary); cursor: pointer;
  background: var(--primary-light); border: none; padding: 1px 6px; border-radius: 8px;
}
.info-row { display: flex; justify-content: space-between; padding: 2px 0; font-size: 12px; }
.info-row .label { color: var(--text-muted); min-width: 55px; }
.info-row .value { font-weight: 500; text-align: right; flex: 1; }
.allergy-tag {
  display: inline-block; background: var(--danger-light); color: var(--danger);
  font-size: 11px; padding: 1px 6px; border-radius: 3px; margin: 1px 2px; font-weight: 600;
}
.history-item { font-size: 12px; padding: 2px 0; }
.prev-rx-item {
  font-size: 11px; padding: 3px 6px; background: var(--bg);
  border-radius: var(--radius-sm); margin-bottom: 3px;
  display: flex; justify-content: space-between;
}
.do-rx-btn {
  background: var(--success); color: #fff; border: none;
  padding: 4px 10px; border-radius: var(--radius-sm);
  font-size: 11px; font-weight: 600; cursor: pointer; margin-top: 4px; width: 100%;
}
.do-rx-btn:hover { background: #15803d; }
.vehicle-info { background: var(--warning-light); border-radius: var(--radius-sm); padding: 6px 8px; }
.vehicle-info .plate { font-size: 15px; font-weight: 700; }
.patient-memo {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 4px 6px; font-size: 11px; font-family: inherit; resize: none; height: 40px;
}
.patient-memo:focus { outline: none; border-color: var(--primary); }
.patient-thumb {
  width: 40px; height: 40px; border-radius: 50%;
  background: var(--bg); border: 2px solid var(--border);
  display: flex; align-items: center; justify-content: center;
  font-size: 16px; color: var(--text-light); overflow: hidden;
}
.insurance-photo-area {
  border: 2px dashed var(--border); border-radius: var(--radius-sm);
  padding: 8px; text-align: center; cursor: pointer; min-height: 50px;
  display: flex; flex-direction: column; align-items: center; justify-content: center; gap: 4px;
}
.insurance-photo-area:hover { border-color: var(--primary); }
.insurance-photo-area img { max-width: 100%; max-height: 80px; border-radius: var(--radius-sm); }
.prev-visit-link {
  display: inline-block; font-size: 11px; color: var(--primary);
  cursor: pointer; text-decoration: underline; margin-top: 2px;
}
.questionnaire-badge { display: inline-block; font-size: 10px; padding: 1px 6px; border-radius: 8px; font-weight: 600; }
.questionnaire-badge.received { background: var(--success-light); color: var(--success); }
.questionnaire-badge.pending { background: var(--warning-light); color: var(--warning); }
.questionnaire-data { background: var(--bg); border-radius: var(--radius-sm); padding: 6px 8px; font-size: 11px; }
.questionnaire-data .q-row { padding: 2px 0; display: flex; justify-content: space-between; }
.questionnaire-data .q-label { color: var(--text-muted); }

/* History tab styles */
.history-entry {
  padding: 5px 0; border-bottom: 1px solid var(--bg); font-size: 11px;
  display: flex; justify-content: space-between; gap: 4px;
}
.history-entry:last-child { border-bottom: none; }
.history-date { color: var(--primary); font-weight: 600; min-width: 70px; }
.history-diag { flex: 1; }
.history-doc { color: var(--text-muted); min-width: 40px; text-align: right; }

/* ===== Center: Karte (Left-Right Split) ===== */
.karte-center-panel { grid-row: 1; grid-column: 3; min-width: 0; }
.karte-center-body { padding: 8px 10px; }

.form-group { margin-bottom: 6px; }
.form-label { font-size: 11px; font-weight: 600; color: var(--text-muted); margin-bottom: 2px; display: block; }
.form-input, .form-textarea {
  width: 100%; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 5px 8px; font-size: 13px; font-family: inherit; transition: border 0.15s;
}
.form-input:focus, .form-textarea:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 2px var(--primary-light); }
.form-textarea { resize: none; }
.chief-complaint-wrap { display: flex; gap: 4px; }
.chief-complaint-wrap select {
  width: 140px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  padding: 5px 4px; font-size: 12px; font-family: inherit; cursor: pointer;
}
.chief-complaint-wrap input { flex: 1; }

/* ===== Karte Left-Right Split (Phase 1+2) ===== */
.karte-split {
  display: grid; grid-template-columns: 1fr 6px 1fr; gap: 0;
  margin-bottom: 6px;
}
.karte-split-col {
  border: 1px solid var(--border); border-radius: var(--radius); overflow: hidden;
}
.karte-split-title {
  background: var(--bg); padding: 4px 10px; font-size: 11px; font-weight: 700;
  color: var(--text-muted); border-bottom: 1px solid var(--border);
}

/* Rich Text Editor (Phase 2) */
.richtext-toolbar {
  display: flex; gap: 3px; padding: 4px 6px;
  border-bottom: 1px solid var(--border); background: var(--bg);
  flex-wrap: wrap;
}
.rt-btn {
  width: 26px; height: 26px; border: 1px solid var(--border); border-radius: 3px;
  background: var(--card); font-size: 12px; cursor: pointer;
  display: flex; align-items: center; justify-content: center;
}
.rt-btn:hover { background: var(--primary-light); }
.rt-color-black { color: #000; font-weight: 700; }
.rt-color-red { color: var(--danger); font-weight: 700; }
.rt-color-blue { color: var(--primary); font-weight: 700; }
.rt-sep { width: 1px; background: var(--border); margin: 2px 3px; }
.richtext-editor {
  min-height: 100px; padding: 8px 10px; font-size: 13px; line-height: 1.8;
  outline: none; overflow-y: auto; max-height: none; height: 160px;
  resize: vertical;
}
.richtext-editor:empty::before {
  content: attr(data-placeholder); color: var(--text-light); white-space: pre-line;
}
.richtext-editor:focus { box-shadow: inset 0 0 0 2px var(--primary-light); }

/* Actions body (right side of split) */
.actions-body { padding: 8px 10px; }

/* Vitals */
.vital-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; }
.vital-item { display: flex; align-items: center; gap: 3px; background: var(--bg); padding: 3px 5px; border-radius: var(--radius-sm); }
.vital-item label { font-size: 11px; font-weight: 600; color: var(--text-muted); min-width: 30px; }
.vital-item input { width: 100%; border: 1px solid var(--border); border-radius: 3px; padding: 2px 4px; font-size: 12px; text-align: center; font-family: inherit; }
.vital-item input:focus { outline: none; border-color: var(--primary); }
.vital-item .unit { font-size: 10px; color: var(--text-muted); min-width: 26px; }
.bp-group { display: flex; align-items: center; gap: 2px; flex: 1; }
.bp-group input { width: 45%; }
.bp-group .slash { color: var(--text-muted); font-size: 14px; }

/* Disease */
.disease-search-wrap { position: relative; }
.disease-results { position: absolute; top: 100%; left: 0; right: 0; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); max-height: 120px; overflow-y: auto; z-index: 50; box-shadow: var(--shadow-lg); display: none; }
.disease-results.show { display: block; }
.disease-result-item { padding: 5px 8px; cursor: pointer; font-size: 12px; border-bottom: 1px solid var(--bg); }
.disease-result-item:hover { background: var(--primary-light); }
.disease-quick-btns { display: flex; flex-wrap: wrap; gap: 3px; margin-top: 3px; }
.disease-quick-btn { background: var(--bg); border: 1px solid var(--border); padding: 2px 6px; border-radius: 12px; font-size: 10px; cursor: pointer; }
.disease-quick-btn:hover { background: var(--primary-light); border-color: var(--primary); }
.selected-diseases { margin-top: 3px; display: flex; flex-wrap: wrap; gap: 3px; }
.disease-tag { display: inline-flex; align-items: center; gap: 3px; background: var(--purple-light); color: var(--purple); padding: 2px 7px; border-radius: 10px; font-size: 11px; font-weight: 500; }
.disease-tag.suspected { background: var(--warning-light); color: #92400e; border: 1px dashed var(--warning); }
.disease-tag .status-toggle { cursor: pointer; font-size: 10px; padding: 0 2px; opacity: 0.7; }
.disease-tag .status-toggle:hover { opacity: 1; }
.disease-tag .remove { cursor: pointer; font-size: 13px; line-height: 1; opacity: 0.6; }
.disease-tag .remove:hover { opacity: 1; }

/* ===== Prescription ===== */
.set-order-btns { display: grid; grid-template-columns: 1fr 1fr; gap: 3px; margin-bottom: 6px; }
.set-order-btn { background: var(--bg); border: 1px solid var(--border); padding: 5px 4px; border-radius: var(--radius-sm); font-size: 11px; font-weight: 600; cursor: pointer; text-align: center; }
.set-order-btn:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }
.drug-search-wrap { position: relative; margin-bottom: 6px; }
.drug-results { position: absolute; top: 100%; left: 0; right: 0; background: var(--card); border: 1px solid var(--border); border-radius: var(--radius-sm); max-height: 140px; overflow-y: auto; z-index: 50; box-shadow: var(--shadow-lg); display: none; }
.drug-results.show { display: block; }
.drug-result-item { padding: 5px 8px; cursor: pointer; font-size: 12px; border-bottom: 1px solid var(--bg); display: flex; justify-content: space-between; }
.drug-result-item:hover { background: var(--primary-light); }
.drug-result-item .price { color: var(--text-muted); font-size: 11px; }
.rx-list { list-style: none; }
.rx-item { display: flex; align-items: center; gap: 4px; padding: 4px 6px; background: var(--bg); border-radius: var(--radius-sm); margin-bottom: 2px; font-size: 12px; }
.rx-item .name { flex: 1; font-weight: 500; }
.rx-item input { width: 36px; border: 1px solid var(--border); border-radius: 3px; padding: 2px 4px; text-align: center; font-size: 12px; font-family: inherit; }
.rx-item input:focus { outline: none; border-color: var(--primary); }
.rx-item .unit { font-size: 11px; color: var(--text-muted); min-width: 12px; }
.rx-item .remove-drug { color: var(--danger); cursor: pointer; font-size: 15px; line-height: 1; opacity: 0.5; padding: 0 2px; }
.rx-item .remove-drug:hover { opacity: 1; }
.rx-days-row { display: flex; align-items: center; gap: 6px; padding: 4px 0; border-top: 1px solid var(--border); margin-top: 4px; }
.rx-days-row label { font-size: 11px; font-weight: 600; color: var(--text-muted); }
.rx-days-row input { width: 44px; border: 1px solid var(--border); border-radius: 3px; padding: 3px 5px; text-align: center; font-size: 13px; font-family: inherit; }
.rx-days-row .unit { font-size: 12px; color: var(--text-muted); }

/* ===== Right Panel ===== */
.right-panel {
  grid-row: 1; grid-column: 5;
  display: flex; flex-direction: column; overflow: hidden;
}
.right-panel-sections { flex: 1; overflow-y: auto; padding: 0; }
.right-panel-sections::-webkit-scrollbar { width: 4px; }
.right-panel-sections::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }
.right-section { border-bottom: 1px solid var(--border); }
.right-section:last-child { border-bottom: none; }
.right-section-title {
  font-size: 12px; font-weight: 700; text-transform: uppercase; letter-spacing: 1px;
  padding: 6px 10px; border-bottom: 1px solid var(--border);
  display: flex; align-items: center; gap: 6px;
  color: var(--text-muted); background: var(--bg);
  position: sticky; top: 0; z-index: 1;
}
.right-section-title .icon { font-size: 14px; }
.right-section-body { padding: 8px 10px; }

/* ===== Billing Menu Tabs (Phase 4) ===== */
.billing-menu-search {
  margin-bottom: 6px; padding: 4px 8px; font-size: 11px;
}
.billing-menu-tabs {
  display: flex; gap: 2px; margin-bottom: 6px; flex-wrap: wrap;
}
.bm-tab {
  padding: 3px 8px; font-size: 10px; border-radius: 12px;
  border: 1px solid var(--border); background: var(--card);
  color: var(--text-muted); cursor: pointer; font-weight: 600;
}
.bm-tab.active { background: var(--primary); color: #fff; border-color: var(--primary); }
.bm-tab:hover:not(.active) { background: var(--primary-light); }
.billing-menu-items { }
.bm-item {
  display: flex; justify-content: space-between; align-items: center;
  padding: 4px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm);
  margin-bottom: 2px; font-size: 11px; cursor: pointer;
}
.bm-item:hover { background: var(--primary-light); border-color: var(--primary); }
.bm-item .bm-pts { color: var(--primary); font-weight: 600; font-size: 10px; }

/* ===== Billing ===== */
.billing-row { display: flex; justify-content: space-between; padding: 3px 0; font-size: 12px; }
.billing-row .label { color: var(--text-muted); }
.billing-row .value { font-weight: 500; font-variant-numeric: tabular-nums; }
.billing-row .value.surcharge { color: var(--danger); }
.billing-divider { border-top: 1px solid var(--border); margin: 4px 0; }
.billing-total { display: flex; justify-content: space-between; padding: 4px 0; font-size: 14px; font-weight: 700; }
.billing-burden { display: flex; justify-content: space-between; padding: 6px 8px; background: var(--primary-light); border-radius: var(--radius); font-size: 16px; font-weight: 700; color: var(--primary); margin-top: 4px; }
.billing-actions { display: flex; gap: 6px; margin-top: 8px; }

/* ===== Exam + Document ===== */
.exam-check-list { list-style: none; }
.exam-check-item { display: flex; align-items: center; gap: 6px; padding: 3px 0; font-size: 12px; }
.exam-check-item input[type="checkbox"] { cursor: pointer; }
.exam-check-item label { cursor: pointer; flex: 1; }
.exam-check-item .exam-points { font-size: 11px; color: var(--text-muted); min-width: 40px; text-align: right; }
.doc-btns { display: flex; flex-direction: column; gap: 3px; margin-top: 8px; }
.doc-btn { background: var(--bg); border: 1px solid var(--border); padding: 6px 8px; border-radius: var(--radius-sm); font-size: 11px; font-weight: 600; cursor: pointer; text-align: left; display: flex; align-items: center; gap: 6px; }
.doc-btn:hover { background: var(--primary-light); border-color: var(--primary); color: var(--primary); }

/* ===== Waiting Panel ===== */
.waiting-item { display: flex; align-items: center; gap: 6px; padding: 6px 8px; border-radius: var(--radius-sm); cursor: pointer; margin-bottom: 2px; border: 1px solid transparent; }
.waiting-item:hover { background: var(--bg); }
.waiting-item.active { background: var(--primary-light); border-color: var(--primary); }
.waiting-item .status-dot { width: 10px; height: 10px; border-radius: 50%; flex-shrink: 0; }
.status-waiting { background: var(--text-light); }
.status-active { background: var(--success); animation: pulse 1.5s infinite; }
.status-done { background: var(--primary); }
@keyframes pulse { 0%, 100% { opacity: 1; } 50% { opacity: 0.4; } }
.waiting-item .w-info { flex: 1; min-width: 0; }
.waiting-item .w-name { font-size: 12px; font-weight: 600; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.waiting-item .w-detail { font-size: 10px; color: var(--text-muted); }
.waiting-item .w-lane { font-size: 10px; font-weight: 600; background: var(--bg); padding: 2px 6px; border-radius: 8px; color: var(--text-muted); flex-shrink: 0; }
.nav-btns { display: flex; gap: 4px; margin-top: 6px; }
.nav-btn { flex: 1; padding: 8px; border: none; border-radius: var(--radius-sm); font-size: 12px; font-weight: 700; cursor: pointer; font-family: inherit; }
.nav-btn:disabled { opacity: 0.4; cursor: not-allowed; }
.prev-patient-btn { background: var(--bg); color: var(--text); border: 1px solid var(--border); }
.prev-patient-btn:hover:not(:disabled) { background: var(--primary-light); }
.next-patient-btn { background: var(--primary); color: #fff; }
.next-patient-btn:hover:not(:disabled) { background: var(--primary-dark); }
.waiting-stats { display: flex; justify-content: space-around; padding: 4px 0; margin-bottom: 4px; border-bottom: 1px solid var(--border); }
.waiting-stat { text-align: center; }
.waiting-stat .num { font-size: 18px; font-weight: 700; color: var(--primary); }
.waiting-stat .lbl { font-size: 10px; color: var(--text-muted); }

/* ===== Shared ===== */
.btn { flex: 1; padding: 7px 10px; border: none; border-radius: var(--radius-sm); font-size: 12px; font-weight: 600; cursor: pointer; font-family: inherit; }
.btn-primary { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-dark); }
.btn-success { background: var(--success); color: #fff; }
.btn-success:hover { background: #15803d; }
.btn-outline { background: var(--card); color: var(--text); border: 1px solid var(--border); }
.btn-outline:hover { background: var(--bg); }

.toast { position: fixed; top: 56px; right: 16px; background: var(--success); color: #fff; padding: 10px 20px; border-radius: var(--radius); font-size: 13px; font-weight: 600; box-shadow: var(--shadow-lg); z-index: 200; transform: translateX(120%); transition: transform 0.3s ease; }
.toast.show { transform: translateX(0); }

/* Modal */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,0.4); display: none; align-items: center; justify-content: center; z-index: 300; }
.modal-overlay.show { display: flex; }
.modal { background: var(--card); border-radius: var(--radius); padding: 20px; min-width: 400px; max-width: 600px; max-height: 80vh; overflow-y: auto; box-shadow: var(--shadow-lg); }
.modal h3 { font-size: 15px; margin-bottom: 12px; display: flex; align-items: center; gap: 8px; }
.modal-close { margin-left: auto; background: none; border: none; font-size: 20px; cursor: pointer; color: var(--text-muted); }
.modal-close:hover { color: var(--text); }
.modal .modal-actions { display: flex; gap: 8px; margin-top: 16px; justify-content: flex-end; }
.edit-form-row { display: flex; gap: 8px; align-items: center; margin-bottom: 8px; }
.edit-form-row label { font-size: 12px; min-width: 80px; color: var(--text-muted); font-weight: 600; }
.edit-form-row input, .edit-form-row select { flex: 1; padding: 5px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; font-family: inherit; }
.req { color: var(--danger); font-size: 10px; margin-left: 2px; }
.auto-field { background: var(--primary-light); border-color: var(--primary) !important; color: var(--primary); font-weight: 600; }
.radio-group { display: flex; gap: 16px; flex: 1; }
.radio-label { display: flex; align-items: center; gap: 4px; font-size: 13px; cursor: pointer; }
.addr-grid { flex: 1; display: flex; flex-direction: column; gap: 4px; }
.addr-zip-row { display: flex; align-items: center; gap: 8px; }
.addr-detail-row { display: flex; gap: 4px; }
.addr-grid input { padding: 5px 8px; border: 1px solid var(--border); border-radius: var(--radius-sm); font-size: 13px; font-family: inherit; }
.addr-grid input:focus { outline: none; border-color: var(--primary); }

/* ===== v0.4: Insurance Calc Result ===== */
.calc-result { font-size: 12px; line-height: 1.6; }
.calc-section { margin-bottom: 8px; padding: 8px 10px; background: var(--bg); border-radius: var(--radius-sm); }
.calc-section:last-child { margin-bottom: 0; }
.calc-label { font-size: 11px; font-weight: 700; color: var(--text-muted); text-transform: uppercase; letter-spacing: 0.05em; margin-bottom: 4px; }
.calc-row { display: flex; align-items: center; gap: 8px; padding: 2px 0; }
.calc-mono { font-family: 'Consolas', 'SF Mono', monospace; font-weight: 600; letter-spacing: 0.1em; }
.calc-ok { color: var(--success); font-weight: 700; font-size: 11px; }
.calc-ng { color: var(--danger); font-weight: 700; font-size: 11px; }
.calc-rate { font-size: 28px; font-weight: 900; color: var(--primary); line-height: 1.2; margin-bottom: 4px; }
.calc-rule { font-size: 12px; color: var(--text); font-weight: 600; }
.calc-detail { font-size: 11px; color: var(--text-muted); padding-left: 8px; }
.calc-warnings { background: #fef9c3; border: 1px solid #fde68a; }
.calc-warning { font-size: 11px; color: #92400e; padding: 2px 0; }

/* ===== OCR Section ===== */
.ocr-section {
  background: linear-gradient(135deg, #eff6ff 0%, #f0fdf4 100%);
  border: 1px dashed var(--primary);
  border-radius: 10px;
  padding: 12px 14px;
  margin-bottom: 14px;
}
.ocr-header {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 8px;
}
.ocr-icon { font-size: 18px; }
.ocr-header > span:nth-child(2) {
  font-weight: 700;
  font-size: 13px;
  color: var(--primary);
  flex: 1;
}
.btn-sm {
  padding: 3px 10px;
  font-size: 11px;
  border-radius: 5px;
}
.ocr-preview-row {
  display: flex;
  gap: 12px;
  align-items: flex-start;
}
.ocr-preview-row > img {
  flex-shrink: 0;
  max-width: 45%;
  object-fit: contain;
}
.ocr-result-panel {
  flex: 1;
  min-width: 0;
  font-size: 12px;
}
.ocr-progress-bar {
  height: 6px;
  background: #e2e8f0;
  border-radius: 3px;
  overflow: hidden;
  margin-bottom: 4px;
}
.ocr-progress-fill {
  height: 100%;
  background: var(--primary);
  border-radius: 3px;
  width: 0%;
  transition: width 0.3s;
}
.ocr-field-row {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 2px 0;
  font-size: 12px;
}
.ocr-field-label {
  font-weight: 600;
  color: var(--text-muted);
  min-width: 70px;
  flex-shrink: 0;
}
.ocr-field-value {
  font-weight: 700;
  color: var(--text);
  word-break: break-all;
}
.ocr-field-value.low-conf {
  color: var(--warning);
}
.ocr-field-check {
  color: var(--success);
  font-size: 11px;
}
.ocr-field-warn {
  color: var(--warning);
  font-size: 11px;
}
.ocr-guess-hint {
  font-size: 10px;
  color: var(--primary);
  margin-left: 4px;
  cursor: pointer;
  text-decoration: underline;
  white-space: nowrap;
}

/* ========================================
   音声カルテ (Whisper-Karte) セクション
   ======================================== */
.whisper-section {
  margin: 0 0 8px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: #f0fdf4;
  overflow: hidden;
}
.whisper-header {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 6px 10px;
  background: linear-gradient(135deg, #059669 0%, #10b981 100%);
  color: #fff;
  font-size: 12px;
  flex-wrap: wrap;
}
.whisper-title {
  font-weight: 700;
  font-size: 13px;
  margin-right: 4px;
}
.whisper-controls {
  display: flex;
  align-items: center;
  gap: 6px;
  flex-wrap: wrap;
}
.whisper-mic-select {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.15);
  color: #fff;
  max-width: 150px;
}
.whisper-mic-select option { color: #000; }
.whisper-rec-btn {
  display: flex;
  align-items: center;
  gap: 4px;
  padding: 3px 10px;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 4px;
  background: rgba(255,255,255,0.15);
  color: #fff;
  font-size: 12px;
  font-weight: 600;
  cursor: pointer;
  transition: all 0.2s;
}
.whisper-rec-btn:hover:not(:disabled) { background: rgba(255,255,255,0.3); }
.whisper-rec-btn:disabled { opacity: 0.5; cursor: default; }
.whisper-rec-btn.recording {
  background: var(--danger);
  border-color: var(--danger);
  animation: rec-pulse 1s ease-in-out infinite;
}
@keyframes rec-pulse {
  0%, 100% { opacity: 1; }
  50% { opacity: 0.7; }
}
.rec-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  border-radius: 50%;
  background: rgba(255,255,255,0.6);
}
.rec-dot.active { background: #fff; }
.whisper-time {
  font-family: 'Courier New', monospace;
  font-size: 12px;
  font-weight: 600;
  min-width: 40px;
}
.whisper-prompt-select {
  font-size: 11px;
  padding: 2px 6px;
  border-radius: 4px;
  border: 1px solid rgba(255,255,255,0.3);
  background: rgba(255,255,255,0.15);
  color: #fff;
  max-width: 120px;
}
.whisper-prompt-select option { color: #000; }
.whisper-gen-btn, .whisper-apply-btn {
  padding: 3px 10px;
  border: 1px solid rgba(255,255,255,0.4);
  border-radius: 4px;
  background: rgba(255,255,255,0.2);
  color: #fff;
  font-size: 11px;
  font-weight: 600;
  cursor: pointer;
  white-space: nowrap;
}
.whisper-gen-btn:hover:not(:disabled), .whisper-apply-btn:hover:not(:disabled) {
  background: rgba(255,255,255,0.35);
}
.whisper-gen-btn:disabled, .whisper-apply-btn:disabled {
  opacity: 0.5;
  cursor: default;
}
.whisper-apply-btn { background: rgba(37,99,235,0.6); }
.whisper-body {
  padding: 8px 10px;
}
.whisper-transcript-area, .whisper-karte-area {
  margin-bottom: 6px;
}
.whisper-label {
  display: flex;
  justify-content: space-between;
  align-items: center;
  font-size: 11px;
  font-weight: 600;
  color: var(--text-muted);
  margin-bottom: 3px;
}
.whisper-copy-btn {
  font-size: 10px;
  padding: 1px 6px;
  border: 1px solid var(--border);
  border-radius: 3px;
  background: var(--card);
  cursor: pointer;
  color: var(--text-muted);
}
.whisper-copy-btn:hover { background: var(--bg); }
.whisper-textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 6px 8px;
  font-size: 12px;
  font-family: inherit;
  resize: vertical;
  background: var(--card);
}
.whisper-textarea:focus {
  outline: none;
  border-color: var(--primary);
}
.whisper-status {
  font-size: 11px;
  color: var(--text-muted);
  min-height: 16px;
}
.whisper-status-success { color: var(--success); }
.whisper-status-error { color: var(--danger); }
.whisper-status-recording { color: var(--danger); font-weight: 600; }
.whisper-status-processing { color: var(--warning); }
.whisper-separator {
  color: rgba(255,255,255,0.4);
  margin: 0 4px;
  font-size: 14px;
}
.whisper-upload-btn {
  display: inline-block;
  padding: 6px 14px;
  border-radius: 6px;
  font-size: 13px;
  font-weight: 700;
  background: #fff;
  color: #059669;
  cursor: pointer;
  border: 2px solid #fff;
  transition: background 0.15s, transform 0.1s;
  box-shadow: 0 2px 6px rgba(0,0,0,0.15);
}
.whisper-upload-btn:hover { background: #ecfdf5; transform: translateY(-1px); }
.whisper-upload-btn:active { transform: translateY(0); }
.whisper-file-name {
  font-size: 11px;
  color: rgba(255,255,255,0.8);
  max-width: 120px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

/* v0.8: Sort buttons */
.sort-btn {
  font-size: 10px;
  padding: 2px 6px;
  border: 1px solid var(--border);
  border-radius: 4px;
  background: var(--card);
  cursor: pointer;
  color: var(--text-muted);
}
.sort-btn:hover { background: var(--primary-light); color: var(--primary); }
.sort-btn.sort-active { background: var(--primary); color: #fff; border-color: var(--primary); }

/* v0.8: Set order CRUD */
.set-order-del {
  display: inline-block;
  width: 16px;
  height: 16px;
  line-height: 14px;
  text-align: center;
  font-size: 12px;
  color: var(--danger);
  cursor: pointer;
  margin-left: -4px;
  margin-right: 4px;
  border-radius: 50%;
  vertical-align: middle;
}
.set-order-del:hover { background: var(--danger-light); }
.set-order-save, .set-order-manage {
  background: var(--card) !important;
  border: 1px dashed var(--border) !important;
  color: var(--primary) !important;
  font-size: 11px !important;
}
.set-order-save:hover, .set-order-manage:hover { background: var(--primary-light) !important; }

/* Set Order Manager Modal */
.set-manager-modal { max-width: 440px; width: 90vw; max-height: 70vh; overflow-y: auto; }
.set-manager-list { display: flex; flex-direction: column; gap: 4px; }
.set-manager-item { display: flex; align-items: center; gap: 8px; padding: 8px 10px; background: var(--bg); border-radius: var(--radius-sm); border: 1px solid var(--border); }
.set-manager-info { flex: 1; min-width: 0; }
.set-manager-name { font-size: 12px; font-weight: 600; color: var(--text); display: block; }
.set-manager-detail { font-size: 10px; color: var(--text-muted); display: block; margin-top: 2px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; max-width: 300px; }
.set-manager-del { background: none; border: 1px solid var(--danger); color: var(--danger); font-size: 10px; padding: 2px 8px; border-radius: var(--radius-sm); cursor: pointer; }
.set-manager-del:hover { background: var(--danger-light); }
.set-manager-close { background: var(--primary); color: #fff; border: none; padding: 6px 18px; border-radius: var(--radius-sm); cursor: pointer; font-size: 12px; }
.set-manager-close:hover { opacity: 0.9; }

/* Billing MyList */
.bm-tab-mylist { color: #d97706 !important; font-weight: 700; }
.bm-tab-mylist.active { background: #fef3c7 !important; border-color: #d97706 !important; color: #92400e !important; }
.bm-item { display: flex; align-items: center; gap: 4px; }
.bm-item-label { flex: 1; cursor: pointer; }
.bm-fav-btn { color: #d1d5db; font-size: 14px; cursor: pointer; flex-shrink: 0; line-height: 1; padding: 2px; }
.bm-fav-btn:hover { color: #d97706; }
.bm-fav-active { color: #d97706 !important; }
.bm-mylist-item { display: flex; align-items: center; gap: 4px; }
.bm-mylist-del { color: var(--danger); font-size: 14px; cursor: pointer; padding: 0 4px; line-height: 1; flex-shrink: 0; }
.bm-mylist-del:hover { color: #b91c1c; }
.bm-mylist-header { display: flex; align-items: center; gap: 6px; padding: 4px 6px; margin-bottom: 4px; background: #fef9ee; border: 1px solid #fde68a; border-radius: var(--radius-sm); }
.bm-mylist-name { font-size: 12px; font-weight: 700; color: #92400e; cursor: pointer; flex: 1; }
.bm-mylist-name:hover { text-decoration: underline; }
.bm-mylist-nav { display: flex; align-items: center; gap: 4px; }
.bm-mylist-nav-btn { cursor: pointer; font-size: 10px; color: #d97706; padding: 2px 4px; border-radius: 3px; }
.bm-mylist-nav-btn:hover { background: #fde68a; }
.bm-mylist-actions { display: flex; gap: 2px; }
.bm-mylist-action-btn { cursor: pointer; font-size: 13px; color: #d97706; padding: 1px 5px; border-radius: 3px; line-height: 1.2; }
.bm-mylist-action-btn:hover { background: #fde68a; }
.bm-mylist-action-del { color: var(--danger); }
.bm-mylist-action-del:hover { background: var(--danger-light); }

/* v0.8: Added billing list */
.added-billing-list { margin-top: 4px; }
.added-billing-item {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 3px 6px;
  font-size: 11px;
  background: var(--primary-light);
  border-radius: 4px;
  margin-bottom: 3px;
}
.added-billing-item span:first-child { flex: 1; }
.added-billing-pts { color: var(--primary); font-weight: 600; font-size: 10px; }
.added-billing-del {
  cursor: pointer;
  color: var(--danger);
  font-size: 14px;
  line-height: 1;
  padding: 0 2px;
}
.added-billing-del:hover { color: #b91c1c; }

/* v0.8: Rx item days input */
.rx-item input[type="number"] {
  border: 1px solid var(--border);
  border-radius: 4px;
  padding: 2px 4px;
  font-size: 12px;
  text-align: center;
}
