:root {
  color-scheme: light dark;
  --bg: #f3f6fa;
  --card-bg: #ffffff;
  --text: #20364b;
  --muted: #63758a;
  --accent: #184976;
  --accent-soft: #eaf3f9;
  --brand-cyan: #0fa5d8;
  --ok: #15803d;
  --err: #b42338;
  --border: #dce5ee;
  --shadow: 0 4px 20px -8px rgb(24 73 118 / 12%);
}
@media (prefers-color-scheme: dark) {
  :root {
    --bg: #101b27;
    --card-bg: #182838;
    --text: #e4edf5;
    --muted: #a2b5c7;
    --accent: #184976;
    --accent-soft: #203b50;
    --brand-cyan: #54c7ed;
    --ok: #4ade80;
    --err: #f87171;
    --border: #2d4255;
    --shadow: none;
  }
}
* { box-sizing: border-box; }
@media (prefers-reduced-motion: reduce) {
  *, *::before, *::after {
    animation-duration: 0.001ms !important;
    transition-duration: 0.001ms !important;
  }
}
body {
  margin: 0;
  font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
  font-size: 16px;
  line-height: 1.5;
  background: var(--bg);
  color: var(--text);
  padding: 0 28px 24px;
  max-width: 824px;
  margin-inline: auto;
}
h1 {
  font-size: clamp(1.65rem, 4vw, 2rem);
  margin: 0 0 8px;
  letter-spacing: -0.035em;
  line-height: 1.2;
}
p.subtitle {
  color: var(--muted);
  margin: 0;
  font-size: 0.98rem;
}
button, input { font: inherit; }
button { -webkit-tap-highlight-color: transparent; touch-action: manipulation; }
button:disabled { cursor: not-allowed; }
:focus-visible { outline: 3px solid var(--brand-cyan); outline-offset: 3px; }
svg { fill: none; stroke: currentColor; stroke-width: 1.7; stroke-linecap: round; stroke-linejoin: round; }

/* Marka ve ana menu. Logo kendi renklerini karanlik temada da korur. */
.brand-header {
  display: flex;
  align-items: center;
  gap: 24px;
  padding: 26px 0;
  margin-bottom: 30px;
  border-bottom: 1px solid var(--border);
}
.brand-logo {
  flex: 0 0 206px;
  padding: 12px;
  background: #fff;
  border-radius: 12px;
}
.brand-logo img { display: block; width: 100%; height: auto; }
.brand-title { min-width: 0; padding-left: 24px; border-left: 1px solid var(--border); }
.brand-title p { margin: 0; font-size: 1.1rem; font-weight: 700; }
.brand-title span { display: block; margin-top: 3px; color: var(--muted); font-size: 0.8rem; }
.page-intro { margin-bottom: 24px; }
.connection-card {
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 20px;
  padding: 22px;
  border: 1px solid var(--border);
  border-top: 3px solid var(--brand-cyan);
  border-radius: 16px;
  background: var(--card-bg);
  box-shadow: var(--shadow);
}
.connection-info { display: flex; align-items: center; gap: 14px; min-width: 0; flex: 1 1 240px; }
.connection-icon, .action-icon {
  display: grid;
  place-items: center;
  flex-shrink: 0;
  width: 46px;
  height: 46px;
  border-radius: 12px;
  color: var(--accent);
  background: var(--accent-soft);
}
.connection-icon svg, .action-icon svg { width: 24px; height: 24px; }
.connection-copy { min-width: 0; }
.connection-copy h2 { margin: 0 0 4px; font-size: 1rem; font-weight: 600; }
.section-title { font-size: 1.05rem; margin: 28px 0 12px; }
.action-grid { display: grid; grid-template-columns: repeat(2, minmax(0, 1fr)); gap: 14px; }
.settings-footer { margin-top: 26px; padding-top: 20px; border-top: 1px solid var(--border); }
.settings-footer p { margin: 0 0 10px; font-size: 0.85rem; color: var(--muted); }

.view { display: none; }
.view.active {
  display: block;
  animation: view-in 0.3s cubic-bezier(0.16, 1, 0.3, 1);
}
@keyframes view-in {
  from { opacity: 0; transform: translateY(8px); }
  to { opacity: 1; transform: translateY(0); }
}

.btn-row { display: flex; flex-wrap: wrap; gap: 10px; }
button#connectBtn, button#disconnectBtn {
  flex: 1;
  min-height: 48px;
  padding: 12px 20px;
  font-size: 0.95rem;
  font-weight: 600;
  border: none;
  border-radius: 10px;
  white-space: nowrap;
  cursor: pointer;
  transition: transform 0.15s ease, box-shadow 0.15s ease, opacity 0.2s ease;
}
button#connectBtn {
  background: var(--accent);
  color: white;
  box-shadow: 0 2px 10px -4px color-mix(in srgb, var(--accent) 60%, transparent);
}
button#disconnectBtn {
  background: var(--card-bg);
  color: var(--err);
  border: 1px solid var(--border);
  display: none;
}
button#connectBtn:active, button#disconnectBtn:active { transform: scale(0.97); }
button#connectBtn:disabled { opacity: 0.6; cursor: default; transform: none; }

#status {
  display: flex;
  align-items: center;
  gap: 8px;
  font-size: 0.87rem;
  color: var(--muted);
  transition: color 0.3s ease;
}
#statusText { overflow-wrap: anywhere; }
.status-dot {
  display: inline-block;
  width: 8px;
  height: 8px;
  flex-shrink: 0;
  border-radius: 50%;
  background: var(--muted);
  transition: background 0.3s ease, box-shadow 0.3s ease;
}
.status-dot.connected {
  background: var(--ok);
  box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 50%, transparent);
  animation: pulse-ring 1.8s ease-out 1;
}
@keyframes pulse-ring {
  0%   { box-shadow: 0 0 0 0 color-mix(in srgb, var(--ok) 55%, transparent); }
  100% { box-shadow: 0 0 0 8px color-mix(in srgb, var(--ok) 0%, transparent); }
}

.menu-btn {
  display: block;
  width: 100%;
  min-height: 48px;
  padding: 16px 20px;
  border-radius: 12px;
  border: none;
  background: var(--accent);
  color: white;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  transition: transform 0.15s ease, opacity 0.2s ease;
}
.menu-btn:not(:disabled):active { transform: scale(0.98); }
.menu-btn:disabled { opacity: 0.55; transform: none; }
.menu-action {
  display: grid;
  grid-template-columns: 46px minmax(0, 1fr) 16px;
  align-items: center;
  gap: 14px;
  min-height: 142px;
  padding: 22px 18px;
  border: 1px solid var(--border);
  border-radius: 16px;
  background: var(--card-bg);
  color: var(--text);
  box-shadow: var(--shadow);
  text-align: left;
  transition: border-color 0.2s ease, transform 0.2s ease, box-shadow 0.2s ease;
}
.action-copy { min-width: 0; }
.action-copy strong { display: block; font-size: 1.02rem; font-weight: 650; line-height: 1.35; }
.action-copy > span { display: block; margin-top: 6px; color: var(--muted); font-size: 0.83rem; font-weight: 400; line-height: 1.5; }
.action-arrow { width: 16px; height: 16px; color: var(--muted); }
.menu-action:disabled { opacity: 1; box-shadow: none; background: color-mix(in srgb, var(--card-bg) 55%, var(--bg)); }
.menu-action:disabled .action-icon { color: var(--muted); background: var(--bg); }
.menu-action:disabled .action-arrow { opacity: 0.35; }
@media (hover: hover) {
  .menu-action:not(:disabled):hover { border-color: var(--brand-cyan); transform: translateY(-2px); box-shadow: 0 8px 22px -12px var(--accent); }
  #connectBtn:not(:disabled):hover { filter: brightness(1.12); }
}

.view-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 12px;
  margin-bottom: 22px;
}
.view-header h2 { margin: 0; font-size: 1.3rem; line-height: 1.3; text-align: center; }
.header-btn {
  border: 1px solid var(--border);
  background: var(--card-bg);
  color: var(--text);
  border-radius: 10px;
  padding: 10px 16px;
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
  min-height: 44px;
  flex-shrink: 0;
  transition: transform 0.1s ease, background-color 0.15s ease;
}
.header-btn.refresh { color: var(--accent); font-size: 1.4rem; padding: 8px 16px; line-height: 1; }
.header-btn:active { transform: scale(0.93); }

.card {
  background: var(--card-bg);
  border: 1px solid var(--border);
  border-radius: 16px;
  padding: 24px;
  margin-bottom: 18px;
  box-shadow: var(--shadow);
}
.card h3 {
  display: flex;
  align-items: center;
  flex-wrap: wrap;
  gap: 8px;
  font-size: 1.05rem;
  color: var(--text);
  margin: 0 0 12px;
}
.record-count { border-radius: 6px; background: var(--accent-soft); color: var(--muted); padding: 3px 8px; font-size: 0.73rem; font-weight: 600; }
.field-group {
  padding: 16px 0;
  border-bottom: 1px solid var(--border);
}
.field-group:last-child { border-bottom: none; }
.field-group:first-child { padding-top: 0; }
.field-group:last-child { padding-bottom: 0; }
.row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  flex-wrap: wrap;
  gap: 6px 12px;
}
.row .label { color: var(--text); font-size: 0.95rem; }
.hint {
  margin: 6px 0 0;
  font-size: 0.82rem;
  line-height: 1.6;
  color: var(--muted);
}
.row .value-wrap { display: flex; align-items: center; gap: 6px; max-width: 100%; min-width: 0; margin-left: auto; }
.row .value {
  font-weight: 600;
  font-size: 1.05rem;
  font-variant-numeric: tabular-nums;
  overflow-wrap: anywhere;
  min-width: 0;
  max-width: 100%;
  margin-left: auto;
  border-radius: 6px;
  padding: 3px 8px;
  transition: background-color 0.4s ease, color 0.4s ease;
}
.row .value.editable-value { cursor: pointer; }
.row .value.editable-value:hover { background-color: var(--accent-soft); color: var(--accent); }
.row .value.flash { background-color: var(--accent-soft); color: var(--accent); }

.value-input {
  width: 100px;
  min-width: 0;
  min-height: 44px;
  font-size: 1rem;
  font-weight: 600;
  padding: 4px 8px;
  border-radius: 6px;
  border: 1px solid var(--accent);
  background: var(--accent-soft);
  color: var(--text);
  text-align: right;
}
[data-field="rtc"] .value-input { width: 240px; }
.icon-btn {
  border: none;
  background: transparent;
  color: var(--muted);
  cursor: pointer;
  font-size: 1.3rem;
  line-height: 1;
  min-width: 44px;
  min-height: 44px;
  flex-shrink: 0;
  padding: 6px 8px;
  border-radius: 8px;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.icon-btn:hover { background: var(--accent-soft); color: var(--accent); }
.icon-btn:active { transform: scale(0.9); }
.confirm-icon { color: var(--ok); display: none; }

.history-row {
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 10px 0;
  border-bottom: 1px solid var(--border);
  gap: 12px;
  flex-wrap: wrap;
  overflow-wrap: anywhere;
}
.history-row:last-child { border-bottom: none; }
.history-row.history-empty { opacity: 0.6; }
/* Hala suren olay: kapanmis kayitlardan ayirt edilsin. */
.history-row.history-ongoing .history-value { color: #d97706; }
.history-date { color: var(--muted); font-size: 0.85rem; }
.history-value { font-weight: 600; font-size: 0.95rem; font-variant-numeric: tabular-nums; }

#errorBox {
  display: none;
  background: #fee2e2;
  color: #991b1b;
  border-radius: 10px;
  padding: 12px;
  margin: 16px 0;
  font-size: 0.85rem;
  animation: shake 0.4s ease;
  overflow-wrap: anywhere;
}
@keyframes shake {
  0%, 100% { transform: translateX(0); }
  25% { transform: translateX(-4px); }
  75% { transform: translateX(4px); }
}

/* --- Onay penceresi (silme / sıfırlama gibi geri alınamaz işlemler icin,
   hicbir zaman dogrudan tiklamayla calismaz) --- */
.modal-overlay {
  display: none;
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.5);
  z-index: 100;
  align-items: center;
  justify-content: center;
  padding: 20px;
}
.modal-overlay.active { display: flex; }
.modal-box {
  background: var(--card-bg);
  border-radius: 14px;
  padding: 22px;
  max-width: 420px;
  width: 100%;
  box-shadow: 0 10px 40px rgba(0,0,0,0.3);
}
.modal-box p { margin: 0 0 18px; font-size: 1.02rem; line-height: 1.4; }
.modal-btn-row { display: flex; gap: 10px; }
.modal-btn-row button {
  flex: 1;
  padding: 13px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--accent-soft);
  color: var(--text);
  font-size: 1rem;
  font-weight: 600;
  cursor: pointer;
}
.modal-btn-row button.danger {
  background: var(--err);
  border-color: var(--err);
  color: #fff;
}
.modal-btn-row button.primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #fff;
}
.password-dialog {
  width: min(420px, calc(100% - 32px));
  border: 1px solid var(--border);
  border-radius: 14px;
  padding: 22px;
  color: var(--text);
  background: var(--card-bg);
}
.password-dialog::backdrop { background: rgba(0, 0, 0, 0.5); }
.password-dialog h2 { margin-top: 0; font-size: 1.25rem; }
.password-dialog p { color: var(--muted); font-size: 0.95rem; }
.password-dialog label { display: block; margin-bottom: 8px; }
#devicePassword {
  width: 100%;
  margin-bottom: 20px;
  padding: 12px;
  border: 1px solid var(--border);
  border-radius: 8px;
  background: var(--bg);
  color: var(--text);
  font: inherit;
}
.toast {
  position: fixed;
  top: 16px;
  left: 50%;
  transform: translateX(-50%);
  z-index: 200;
  width: min(600px, calc(100% - 32px));
  border: 1px solid currentColor;
  border-radius: 12px;
  padding: 16px 60px 16px 16px;
  overflow-wrap: anywhere;
  box-shadow: 0 4px 20px rgba(0, 0, 0, 0.18);
}
.toast.success { color: #166534; background: #dcfce7; }
.toast.error { color: #991b1b; background: #fee2e2; }
#toastClose {
  position: absolute;
  top: 4px;
  right: 8px;
  width: 44px;
  height: 44px;
  border: 0;
  background: transparent;
  color: inherit;
  font-size: 1.4rem;
  cursor: pointer;
}

.danger-btn {
  background: none;
  border: 1px solid color-mix(in srgb, var(--err) 40%, var(--border));
  color: var(--err);
  border-radius: 8px;
  min-height: 44px;
  padding: 10px 14px;
  font-size: 0.85rem;
  font-weight: 600;
  cursor: pointer;
  margin-top: 10px;
}
.danger-btn:disabled { opacity: 0.5; }
.danger-btn:not(:disabled):hover { background: color-mix(in srgb, var(--err) 8%, transparent); }

/* --- Load profile tarih-araligi sorgusu (takvim) --- */
.lp-cal-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  margin: 18px 0 10px;
  font-weight: 600;
}
.lp-cal-grid {
  display: grid;
  grid-template-columns: repeat(7, minmax(0, 1fr));
  gap: 4px;
  margin-bottom: 12px;
}
.lp-cal-weekday {
  text-align: center;
  font-size: 0.72rem;
  color: var(--muted);
  padding: 4px 0;
}
.lp-cal-day {
  text-align: center;
  min-height: 44px;
  padding: 11px 0;
  border-radius: 8px;
  font-size: 0.95rem;
  transition: background-color 0.15s ease, color 0.15s ease, transform 0.1s ease;
}
.lp-cal-day.empty { visibility: hidden; }
.lp-cal-day.inactive { color: var(--muted); opacity: 0.3; }
.lp-cal-day.active {
  background: var(--accent-soft);
  color: var(--accent);
  cursor: pointer;
  font-weight: 600;
}
.lp-cal-day.active:active { transform: scale(0.9); }
.lp-cal-day.selected { background: var(--accent); color: #fff; }
.lp-cal-actions {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 10px;
  flex-wrap: wrap;
}

/* --- Firmware guncelleme (OTA) --- */
.ota-file-picker {
  display: block;
  width: 100%;
  padding: 30px 20px;
  margin-bottom: 14px;
  border: 2px dashed var(--border);
  border-radius: 12px;
  text-align: center;
  color: var(--muted);
  cursor: pointer;
  background: var(--card-bg);
  overflow-wrap: anywhere;
}
.ota-file-picker.has-file { border-color: var(--accent); color: var(--accent); font-weight: 600; }
.ota-progress-outer {
  width: 100%;
  height: 14px;
  border-radius: 7px;
  background: var(--accent-soft);
  overflow: hidden;
  margin: 14px 0 8px;
}
.ota-progress-inner {
  height: 100%;
  width: 0%;
  background: var(--accent);
  transition: width 0.2s ease;
}
.ota-progress-inner.error { background: var(--err); }
.ota-progress-inner.done { background: var(--ok); }
#ota-status-text { text-align: center; font-size: 0.95rem; color: var(--muted); margin-bottom: 4px; }

/* HTML'den tasinan baslangic gorunumu ve bolume ozel bosluklar. */
#btnResetDefaults { margin: 0; }

.value-input,
#lpClearSelection,
#ota-file-input,
#ota-progress-wrap {
  display: none;
}

#lpQueryResult {
  margin-top: 12px;
  max-height: 24rem;
  overflow-y: auto;
  scrollbar-gutter: stable;
  scrollbar-color: var(--muted) var(--bg);
  padding: 14px;
  border: 1px solid var(--border);
  border-radius: 10px;
  background: var(--bg);
  font-size: 0.9rem;
}
#lpQueryResult:focus-visible { outline: 2px solid var(--accent); }
.app-footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: 16px;
  margin-top: 32px;
  padding-top: 18px;
  border-top: 1px solid var(--border);
  color: var(--muted);
  font-size: 0.75rem;
}
.app-version { white-space: nowrap; }
.ota-hint { margin-bottom: 14px; }
#btnStartOta { margin-top: 10px; }
#threshold-log, #reset-log { margin: 12px 0; }

@media (prefers-color-scheme: dark) {
  .connection-icon, .action-icon, .icon-btn:hover, .header-btn.refresh,
  .lp-cal-day.active, .ota-file-picker.has-file,
  .row .value.editable-value:hover, .row .value.flash { color: var(--brand-cyan); }
  .lp-cal-day.selected { color: #fff; }
  .history-row.history-ongoing .history-value { color: #fbbf24; }
}

@media (max-width: 600px) {
  body { padding: 0 16px 20px; }
  .brand-header { padding: 20px 0; margin-bottom: 24px; gap: 16px; }
  .brand-logo { flex-basis: 166px; padding: 10px; }
  .brand-title { padding-left: 16px; }
  .brand-title p { font-size: 1rem; }
  .brand-title span { font-size: 0.73rem; }
  .connection-card { padding: 18px; gap: 18px; }
  .connection-card .btn-row { width: 100%; }
  .action-grid { grid-template-columns: 1fr; gap: 12px; }
  .menu-action { min-height: 106px; }
  .card { padding: 18px; }
  .view-header { gap: 8px; }
  .view-header h2 { font-size: 1.12rem; }
  .header-btn { padding: 10px 12px; }
}

@media (max-width: 380px) {
  .brand-header { gap: 12px; }
  .brand-logo { flex-basis: 136px; padding: 8px; }
  .brand-title { padding-left: 12px; }
  .brand-title p { font-size: 0.92rem; }
  .row .value-wrap { flex-basis: 100%; justify-content: flex-end; }
  .modal-btn-row { flex-wrap: wrap; }
  .modal-btn-row button { flex-basis: 100%; }
}
