/* =====================================================================
   track.q64.pl - style (dark theme)
   ===================================================================== */

:root {
    --bg:        #1a1a1a;
    --bg-2:      #232323;
    --bg-3:      #2b2b2b;
    --border:    #3a3a3a;
    --text:      #e8e8e8;
    --text-dim:  #a0a0a0;
    --accent:    #4da6ff;
    --accent-h:  #6fb8ff;
    --success:   #4ade80;
    --error:     #f87171;
    --warn:      #fbbf24;
    --danger:    #dc2626;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    padding: 0;
    height: 100%;
    background: var(--bg);
    color: var(--text);
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
}

body.centered {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    padding: 1rem;
}

/* Karta (logowanie, install) */
.card {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 2rem;
    width: 100%;
}
.card.narrow { max-width: 400px; }

h1 { margin: 0 0 1rem; font-size: 1.5rem; font-weight: 500; }
h2 { margin: 0 0 .75rem; font-size: 1.2rem; font-weight: 500; }

p { margin: 0 0 1rem; }
.muted { color: var(--text-dim); }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-h); text-decoration: underline; }

label {
    display: block;
    margin-bottom: 1rem;
    color: var(--text-dim);
    font-size: .9rem;
}

input[type=text], input[type=password], input[type=email],
input[type=number], input[type=color], input[type=datetime-local],
select, textarea {
    display: block;
    width: 100%;
    margin-top: .3rem;
    padding: .6rem .75rem;
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: 6px;
    color: var(--text);
    font-size: 1rem;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--accent);
}
input[type=color] { height: 40px; padding: .2rem; cursor: pointer; }

button, .btn {
    display: inline-block;
    padding: .6rem 1rem;
    background: var(--accent);
    color: #fff;
    border: none;
    border-radius: 6px;
    font-size: 1rem;
    font-family: inherit;
    font-weight: 500;
    cursor: pointer;
    text-decoration: none;
}
button:hover, .btn:hover { background: var(--accent-h); text-decoration: none; }
button:disabled { opacity: .5; cursor: not-allowed; }
button.secondary, .btn.secondary {
    background: var(--bg-3);
    color: var(--text);
    border: 1px solid var(--border);
}
button.secondary:hover { background: #353535; }
button.danger, .btn.danger { background: var(--danger); }
button.danger:hover { background: #b91c1c; }

.alert {
    padding: .75rem 1rem;
    border-radius: 6px;
    margin-bottom: 1rem;
    font-size: .9rem;
}
.alert.error   { background: rgba(248, 113, 113, .15); color: var(--error); border: 1px solid var(--error); }
.alert.success { background: rgba(74, 222, 128, .15);  color: var(--success); border: 1px solid var(--success); }
.alert.warning { background: rgba(251, 191, 36, .15); color: var(--warn); border: 1px solid var(--warn); }

/* ----- Mapa (map.php) ----- */

body.app {
    display: flex;
    flex-direction: column;
    height: 100vh;
    overflow: hidden;
}

header.topbar {
    display: flex;
    align-items: center;
    gap: 1rem;
    padding: .6rem 1rem;
    background: var(--bg-2);
    border-bottom: 1px solid var(--border);
    flex-shrink: 0;
}
header.topbar .logo {
    font-weight: 500;
    font-size: 1.1rem;
    margin-right: auto;
}
header.topbar nav a {
    margin-right: 1rem;
    color: var(--text-dim);
}
header.topbar nav a.active,
header.topbar nav a:hover { color: var(--text); }

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

.sidebar {
    width: 320px;
    flex-shrink: 0;
    background: var(--bg-2);
    border-right: 1px solid var(--border);
    overflow-y: auto;
    padding: 1rem;
}

#map {
    flex: 1;
    background: #111;
}

.device-item {
    display: flex;
    align-items: center;
    gap: .75rem;
    padding: .6rem;
    margin-bottom: .3rem;
    background: var(--bg-3);
    border: 1px solid var(--border);
    border-radius: 8px;
    cursor: pointer;
    transition: border-color .15s;
}
.device-item:hover, .device-item.active {
    border-color: var(--accent);
}
.device-dot {
    width: 14px;
    height: 14px;
    border-radius: 50%;
    flex-shrink: 0;
}
.device-info { flex: 1; min-width: 0; }
.device-name {
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}
.device-meta {
    font-size: .8rem;
    color: var(--text-dim);
}

/* ----- Panel admin ----- */

.admin-wrap { padding: 2rem; max-width: 1000px; margin: 0 auto; }

table {
    width: 100%;
    border-collapse: collapse;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 8px;
    overflow: hidden;
}
th, td {
    padding: .75rem;
    text-align: left;
    border-bottom: 1px solid var(--border);
}
th { background: var(--bg-3); font-weight: 500; color: var(--text-dim); }
tr:last-child td { border-bottom: none; }

.token-field {
    display: flex;
    gap: .5rem;
    align-items: center;
}
.token-field code {
    background: var(--bg);
    padding: .3rem .5rem;
    border-radius: 4px;
    font-size: .8rem;
    word-break: break-all;
}

/* ----- Tracker PWA ----- */

body.tracker {
    background: var(--bg);
    padding: 1rem;
    font-size: 16px;
}
.tracker-main {
    max-width: 500px;
    margin: 0 auto;
    padding-top: 1rem;
}
.tracker-status {
    padding: 2rem 1rem;
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    text-align: center;
    margin-bottom: 1rem;
}
.tracker-status .dot {
    display: inline-block;
    width: 12px;
    height: 12px;
    border-radius: 50%;
    background: var(--text-dim);
    margin-right: .5rem;
    vertical-align: middle;
}
.tracker-status.active .dot {
    background: var(--success);
    box-shadow: 0 0 0 4px rgba(74, 222, 128, .25);
    animation: pulse 2s infinite;
}
@keyframes pulse {
    0%, 100% { box-shadow: 0 0 0 4px rgba(74, 222, 128, .25); }
    50%      { box-shadow: 0 0 0 10px rgba(74, 222, 128, 0); }
}
.big-btn {
    display: block;
    width: 100%;
    padding: 1.25rem;
    font-size: 1.2rem;
    margin-bottom: .75rem;
}
.tracker-stats {
    background: var(--bg-2);
    border: 1px solid var(--border);
    border-radius: 12px;
    padding: 1rem;
    font-size: .9rem;
}
.tracker-stats dl {
    display: grid;
    grid-template-columns: auto 1fr;
    gap: .4rem 1rem;
    margin: 0;
}
.tracker-stats dt { color: var(--text-dim); }
.tracker-stats dd { margin: 0; font-variant-numeric: tabular-nums; }

/* ----- Leaflet tuning pod dark ----- */

.leaflet-control-attribution,
.leaflet-popup-content-wrapper,
.leaflet-popup-tip {
    background: var(--bg-2) !important;
    color: var(--text) !important;
}
.leaflet-popup-content-wrapper { border: 1px solid var(--border); border-radius: 8px; }
.leaflet-popup-content a { color: var(--accent); }
.leaflet-container { background: #111; }

/* Dark mode dla kafelkow OSM: lekki filtr */
.dark-tiles img.leaflet-tile {
    filter: brightness(0.7) invert(1) contrast(1.1) hue-rotate(200deg) saturate(0.3) brightness(1.1);
}

@media (max-width: 700px) {
    .sidebar { width: 100%; max-height: 40vh; }
    .app-body { flex-direction: column; }
}
