/* ═══════════════════════════════════════════════
   PhoneControl Panel — CSS
   Samsung One UI inspired, dark/light mode
═══════════════════════════════════════════════ */

:root {
  --blue: #1259C3;
  --blue-light: #E8F0FD;
  --blue-dark: #0A3F8C;
  --blue-dim: #5B9CF6;

  --bg: #F4F4F4;
  --surface: #FFFFFF;
  --surface2: #F8F9FA;
  --border: #E0E0E0;
  --text: #1A1A1A;
  --text2: #757575;

  --green: #2E7D32;
  --green-bg: #E8F5E9;
  --red: #C62828;
  --red-bg: #FFEBEE;
  --orange: #E65100;
  --orange-bg: #FFF3E0;

  --radius-sm: 8px;
  --radius-md: 16px;
  --radius-lg: 24px;

  --shadow: 0 1px 4px rgba(0,0,0,0.08);
  --shadow-md: 0 4px 16px rgba(0,0,0,0.12);

  --header-h: 56px;
  --tabs-h: 48px;
}

@media (prefers-color-scheme: dark) {
  :root {
    --blue: #5B9CF6;
    --blue-light: #1A2A4A;
    --blue-dark: #5B9CF6;

    --bg: #1A1A1A;
    --surface: #2C2C2C;
    --surface2: #383838;
    --border: #3A3A3A;
    --text: #EFEFEF;
    --text2: #A0A0A0;

    --green: #66BB6A;
    --green-bg: #1B3A1C;
    --red: #EF5350;
    --red-bg: #3C1A1A;
    --orange: #FFA726;
    --orange-bg: #3A2500;
  }
}

/* ── Reset & Base ─────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html, body {
  height: 100%;
  font-family: -apple-system, 'Samsung One', 'Roboto', sans-serif;
  font-size: 14px;
  background: var(--bg);
  color: var(--text);
  -webkit-font-smoothing: antialiased;
}

button { cursor: pointer; border: none; background: none; font: inherit; color: inherit; }
input  { font: inherit; color: inherit; }
a      { color: var(--blue); text-decoration: none; }

/* ── Screens ──────────────────────────────────── */
.screen { display: none; height: 100dvh; }
.screen.active { display: flex; flex-direction: column; }

/* ═══ LOGIN ═══════════════════════════════════ */
#screen-login {
  align-items: center;
  justify-content: center;
  background: var(--bg);
  padding: 24px;
}

.login-card {
  background: var(--surface);
  border-radius: var(--radius-lg);
  padding: 40px 32px;
  width: 100%;
  max-width: 400px;
  box-shadow: var(--shadow-md);
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 16px;
}

.login-logo svg { width: 72px; height: 72px; }

.login-card h1 {
  font-size: 24px;
  font-weight: 600;
  color: var(--text);
}

.login-subtitle {
  color: var(--text2);
  font-size: 14px;
  text-align: center;
}

.input-group {
  display: flex;
  width: 100%;
  gap: 8px;
  margin-top: 8px;
}

.input-group input {
  flex: 1;
  padding: 12px 16px;
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  background: var(--surface2);
  outline: none;
  font-size: 15px;
  transition: border-color 0.2s;
}
.input-group input:focus { border-color: var(--blue); }

.input-group button {
  padding: 12px 20px;
  background: var(--blue);
  color: #fff;
  border-radius: var(--radius-md);
  font-size: 15px;
  font-weight: 500;
  display: flex;
  align-items: center;
  gap: 8px;
  transition: opacity 0.15s;
}
.input-group button:hover { opacity: 0.88; }

.error-msg {
  width: 100%;
  color: var(--red);
  font-size: 13px;
  background: var(--red-bg);
  padding: 8px 12px;
  border-radius: var(--radius-sm);
  text-align: center;
}
.hidden { display: none !important; }

/* ── Spinner ──────────────────────────────────── */
.spinner {
  width: 16px; height: 16px;
  border: 2px solid rgba(255,255,255,0.3);
  border-top-color: #fff;
  border-radius: 50%;
  animation: spin 0.7s linear infinite;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ═══ HEADER ══════════════════════════════════ */
.header {
  height: var(--header-h);
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0 16px;
  flex-shrink: 0;
  position: sticky;
  top: 0;
  z-index: 100;
}

.header-left { display: flex; align-items: center; gap: 10px; }
.header-logo  { width: 28px; height: 28px; }
.header-title { font-size: 18px; font-weight: 600; }

.header-right { display: flex; align-items: center; gap: 12px; }

/* Status badge */
.status-badge {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 5px 12px;
  border-radius: 20px;
  font-size: 12px;
  font-weight: 500;
  transition: all 0.3s;
}
.status-badge.online  { background: var(--green-bg); color: var(--green); }
.status-badge.offline { background: var(--red-bg);   color: var(--red);   }

.status-dot {
  width: 7px; height: 7px;
  border-radius: 50%;
  background: currentColor;
}
.status-badge.online .status-dot {
  animation: pulse 1.8s ease-in-out infinite;
}
@keyframes pulse {
  0%, 100% { opacity: 1; transform: scale(1); }
  50%       { opacity: 0.5; transform: scale(0.8); }
}

.btn-icon {
  width: 36px; height: 36px;
  display: flex; align-items: center; justify-content: center;
  border-radius: var(--radius-sm);
  color: var(--text2);
  transition: background 0.15s;
}
.btn-icon:hover { background: var(--surface2); }
.btn-icon svg { width: 18px; height: 18px; }

/* ═══ TABS ════════════════════════════════════ */
.tabs {
  display: flex;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}

.tab {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  gap: 3px;
  padding: 10px 8px 8px;
  font-size: 12px;
  color: var(--text2);
  border-bottom: 2.5px solid transparent;
  transition: color 0.2s, border-color 0.2s;
}
.tab svg { width: 20px; height: 20px; stroke: currentColor; }
.tab.active { color: var(--blue); border-bottom-color: var(--blue); }
.tab:hover:not(.active) { background: var(--surface2); }

/* ═══ TAB PANELS ══════════════════════════════ */
.tab-content { flex: 1; overflow: hidden; position: relative; }

.tab-panel {
  display: none;
  height: 100%;
  flex-direction: column;
  overflow: hidden;
}
.tab-panel.active { display: flex; }

/* ═══ GPS ══════════════════════════════════════ */
#tab-gps { flex-direction: column; }

#map {
  flex: 1;
  background: var(--surface2);
  min-height: 200px;
}

.gps-info-bar {
  display: grid;
  grid-template-columns: repeat(4, 1fr);
  background: var(--surface);
  border-top: 1px solid var(--border);
  flex-shrink: 0;
}

.gps-info-item {
  display: flex;
  flex-direction: column;
  align-items: center;
  padding: 10px 8px;
  border-right: 1px solid var(--border);
}
.gps-info-item:last-child { border-right: none; }

.gps-label { font-size: 10px; color: var(--text2); text-transform: uppercase; letter-spacing: 0.5px; }
.gps-value { font-size: 13px; font-weight: 500; margin-top: 2px; }

/* Leaflet marker override */
.phone-marker-icon {
  width: 36px !important;
  height: 36px !important;
  margin-left: -18px !important;
  margin-top: -18px !important;
}
.phone-marker-inner {
  width: 36px;
  height: 36px;
  background: var(--blue, #1259C3);
  border-radius: 50%;
  border: 3px solid #fff;
  box-shadow: 0 2px 8px rgba(0,0,0,0.3);
  display: flex;
  align-items: center;
  justify-content: center;
}
.phone-marker-inner svg { width: 16px; height: 16px; }

/* ═══ TOOLBAR (Kontakty / Połączenia) ══════════ */
.panel-toolbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 10px 12px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
  flex-wrap: wrap;
}

.search-box {
  flex: 1;
  display: flex;
  align-items: center;
  gap: 8px;
  background: var(--surface2);
  border: 1.5px solid var(--border);
  border-radius: var(--radius-md);
  padding: 8px 12px;
  min-width: 160px;
}
.search-box svg { width: 16px; height: 16px; color: var(--text2); flex-shrink: 0; }
.search-box input {
  border: none;
  background: none;
  outline: none;
  flex: 1;
  font-size: 14px;
}

.btn-refresh {
  display: flex;
  align-items: center;
  gap: 6px;
  padding: 8px 14px;
  background: var(--blue-light);
  color: var(--blue);
  border-radius: var(--radius-md);
  font-size: 13px;
  font-weight: 500;
  flex-shrink: 0;
  transition: opacity 0.15s;
}
.btn-refresh svg { width: 14px; height: 14px; }
.btn-refresh:hover { opacity: 0.8; }
.btn-refresh:disabled { opacity: 0.5; cursor: not-allowed; }

/* Filtry połączeń */
.call-filters {
  display: flex;
  gap: 4px;
  flex-wrap: wrap;
}
.filter-btn {
  padding: 6px 12px;
  border-radius: 20px;
  font-size: 12px;
  color: var(--text2);
  background: var(--surface2);
  border: 1px solid var(--border);
  transition: all 0.15s;
}
.filter-btn.active {
  background: var(--blue-light);
  color: var(--blue);
  border-color: var(--blue);
}

/* ═══ LISTY ════════════════════════════════════ */
.list-meta {
  padding: 6px 16px;
  font-size: 12px;
  color: var(--text2);
  background: var(--surface2);
  border-bottom: 1px solid var(--border);
}

.data-list {
  flex: 1;
  overflow-y: auto;
  padding: 8px 12px;
  display: flex;
  flex-direction: column;
  gap: 4px;
}

/* Pusty stan */
.empty-state {
  flex: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  color: var(--text2);
  padding: 40px;
  text-align: center;
}
.empty-state svg { width: 48px; height: 48px; opacity: 0.4; }
.empty-state p   { font-size: 14px; }

/* ── Karta kontaktu ─────────────────────────── */
.contact-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  transition: background 0.1s;
}
.contact-card:hover { background: var(--surface2); }

.contact-avatar {
  width: 40px; height: 40px;
  border-radius: 50%;
  background: var(--blue-light);
  color: var(--blue);
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 16px;
  font-weight: 600;
  flex-shrink: 0;
}

.contact-info { flex: 1; min-width: 0; }
.contact-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.contact-phones {
  font-size: 12px;
  color: var(--text2);
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}

/* ── Karta połączenia ───────────────────────── */
.call-card {
  display: flex;
  align-items: center;
  gap: 12px;
  padding: 10px 12px;
  background: var(--surface);
  border-radius: var(--radius-md);
  border: 1px solid var(--border);
  transition: background 0.1s;
}
.call-card:hover { background: var(--surface2); }

.call-icon {
  width: 40px; height: 40px;
  border-radius: 50%;
  display: flex;
  align-items: center;
  justify-content: center;
  flex-shrink: 0;
}
.call-icon svg { width: 18px; height: 18px; }
.call-icon.incoming  { background: var(--green-bg);  color: var(--green);  }
.call-icon.outgoing  { background: var(--blue-light); color: var(--blue);  }
.call-icon.missed    { background: var(--red-bg);     color: var(--red);   }

.call-info { flex: 1; min-width: 0; }
.call-name {
  font-size: 14px;
  font-weight: 500;
  white-space: nowrap;
  overflow: hidden;
  text-overflow: ellipsis;
}
.call-number {
  font-size: 12px;
  color: var(--text2);
}

.call-meta {
  text-align: right;
  flex-shrink: 0;
}
.call-date     { font-size: 12px; color: var(--text2); }
.call-duration { font-size: 11px; color: var(--text2); margin-top: 2px; }
.call-missed-label {
  font-size: 11px;
  color: var(--red);
  font-weight: 500;
}

/* ═══ TOAST ════════════════════════════════════ */
.toast {
  position: fixed;
  bottom: 24px;
  left: 50%;
  transform: translateX(-50%);
  background: #333;
  color: #fff;
  padding: 10px 20px;
  border-radius: 20px;
  font-size: 13px;
  z-index: 9999;
  pointer-events: none;
  animation: toast-in 0.25s ease;
  white-space: nowrap;
}
.toast.error { background: var(--red); }
.toast.success { background: var(--green); }
@keyframes toast-in { from { opacity: 0; transform: translateX(-50%) translateY(10px); } }

/* ═══ RESPONSIVE ════════════════════════════════ */
@media (max-width: 480px) {
  .gps-info-bar { grid-template-columns: repeat(2, 1fr); }
  .gps-info-item:nth-child(2) { border-right: none; }

  .login-card { padding: 32px 20px; }

  .call-filters { display: none; }

  .panel-toolbar { padding: 8px; }
  .btn-refresh span { display: none; }
  .btn-refresh { padding: 8px; }
}

/* ═══ SCROLLBAR ════════════════════════════════ */
::-webkit-scrollbar { width: 4px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--border); border-radius: 2px; }

/* ═══ LOADING SKELETON ══════════════════════════ */
.skeleton {
  background: linear-gradient(90deg, var(--surface2) 25%, var(--border) 50%, var(--surface2) 75%);
  background-size: 200% 100%;
  animation: shimmer 1.2s infinite;
  border-radius: var(--radius-sm);
}
@keyframes shimmer { to { background-position: -200% 0; } }
