/* =========================================
   Licznik Mediów – dark-first stylesheet
   ========================================= */

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
  --bg:        #0f172a;
  --surface:   #1e293b;
  --surface2:  #334155;
  --border:    #334155;
  --border2:   #475569;
  --text:      #f1f5f9;
  --text-muted:#94a3b8;
  --blue:      #60a5fa;
  --blue-dk:   #3b82f6;
  --blue-bg:   #1e3a5f;
  --green:     #4ade80;
  --green-bg:  #14532d;
  --red:       #f87171;
  --red-bg:    #450a0a;
  --radius:    10px;
  --shadow:    0 1px 6px rgba(0,0,0,.5);
  --font:      -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, sans-serif;
}

/* ---- Light theme overrides ---- */
[data-theme="light"] {
  --bg:        #f8fafc;
  --surface:   #ffffff;
  --surface2:  #f1f5f9;
  --border:    #e2e8f0;
  --border2:   #cbd5e1;
  --text:      #0f172a;
  --text-muted:#64748b;
  --blue:      #2563eb;
  --blue-dk:   #1d4ed8;
  --blue-bg:   #dbeafe;
  --green:     #16a34a;
  --green-bg:  #dcfce7;
  --red:       #dc2626;
  --red-bg:    #fee2e2;
  --shadow:    0 1px 6px rgba(0,0,0,.12);
}

html, body {
  height: 100%;
  font-family: var(--font);
  font-size: 16px;
  line-height: 1.5;
  color: var(--text);
  background: var(--bg);
  -webkit-text-size-adjust: 100%;
  overscroll-behavior: none;
}

/* ---- Layout shell ---- */
#app {
  display: flex;
  flex-direction: column;
  height: 100dvh;
  max-width: 520px;
  margin: 0 auto;
  background: var(--bg);
  overflow: hidden;
}

/* ---- Top bar ---- */
.topbar {
  display: flex;
  align-items: center;
  gap: 8px;
  padding: 12px 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.topbar__title { font-size: 1.05rem; font-weight: 700; flex: 1; color: var(--blue); }
.topbar__user  { font-size: .8rem; color: var(--text-muted); }
.topbar__btn   {
  background: none; border: 1px solid var(--border2); color: var(--text-muted);
  border-radius: 6px; padding: 4px 10px; font-size: .78rem; cursor: pointer;
}
.topbar__btn:hover { background: var(--surface2); color: var(--text); }

.theme-toggle {
  background: none; border: none; color: var(--text-muted);
  cursor: pointer; padding: 4px 6px; border-radius: 6px;
  display: flex; align-items: center; transition: color .15s;
}
.theme-toggle:hover { color: var(--text); background: var(--surface2); }
.theme-toggle svg { width: 18px; height: 18px; }

/* ---- Property tabs ---- */
.prop-tabs {
  display: flex;
  overflow-x: auto;
  scrollbar-width: none;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  flex-shrink: 0;
}
.prop-tabs::-webkit-scrollbar { display: none; }
.prop-tab {
  flex-shrink: 0;
  padding: 8px 16px;
  color: var(--text-muted);
  font-size: .85rem;
  cursor: pointer;
  border-bottom: 2px solid transparent;
  margin-bottom: -1px;
  white-space: nowrap;
  background: none; border-top: none; border-left: none; border-right: none;
  border-radius: 0;
}
.prop-tab:hover   { color: var(--text); }
.prop-tab.active  { color: var(--blue); border-bottom-color: var(--blue); font-weight: 600; }

/* ---- Main content area ---- */
.content { flex: 1; min-height: 0; padding: 16px; overflow-y: auto; }

/* ---- Bottom nav ---- */
.bottom-nav {
  display: flex;
  border-top: 1px solid var(--border);
  background: var(--surface);
  flex-shrink: 0;
}
.bottom-nav__btn {
  flex: 1; display: flex; flex-direction: column; align-items: center;
  gap: 2px; padding: 10px 4px; font-size: .72rem; color: var(--text-muted);
  cursor: pointer; background: none; border: none;
  transition: color .15s;
}
.bottom-nav__btn svg { width: 22px; height: 22px; }
.bottom-nav__btn.active { color: var(--blue); }
.bottom-nav__btn:hover  { color: var(--text); }

/* ---- Cards (entry list) ---- */
.entry-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  margin-bottom: 10px;
  overflow: hidden;
  cursor: pointer;
}
.entry-card__header {
  display: flex; align-items: center; gap: 8px;
  padding: 12px 14px;
}
.entry-card__date { font-weight: 600; font-size: .95rem; min-width: 82px; color: var(--text); }
.entry-card__values { flex: 1; display: flex; flex-wrap: wrap; gap: 6px; }
.entry-card__val {
  font-size: .88rem; background: var(--surface2);
  border: 1px solid var(--border); border-radius: 4px;
  padding: 3px 8px; white-space: nowrap; color: var(--text);
}
.entry-card__val span { color: var(--text-muted); margin-right: 2px; }
.entry-card__actions { display: flex; flex-direction: column; gap: 4px; align-items: center; }

.entry-card__body {
  padding: 0 14px 14px;
  border-top: 1px solid var(--border);
  font-size: .85rem;
}
.entry-card__body h4 {
  margin: 10px 0 6px; color: var(--text-muted);
  font-size: .78rem; text-transform: uppercase; letter-spacing: .05em;
}
.cons-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 6px;
}
.cons-item {
  background: var(--blue-bg); border-radius: 6px; padding: 6px 10px;
}
.cons-item__label { font-size: .72rem; color: var(--blue); margin-bottom: 2px; display:flex; align-items:center; gap:4px; }
.cons-item__value { font-size: 1rem; font-weight: 600; color: var(--text); }
.cons-item__cost  { font-size: .72rem; color: var(--text-muted); margin-top: 1px; }
.cost-total {
  margin-top: 10px; padding: 8px 10px;
  background: var(--green-bg); border-radius: 6px;
  color: var(--green); font-weight: 600; font-size: .9rem;
  display: flex; justify-content: space-between;
}

/* ---- Inline edit form (inside entry card) ---- */
.edit-form {
  padding: 12px 14px;
  border-top: 1px solid var(--border);
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}
.edit-form label { font-size: .75rem; color: var(--text-muted); display: block; margin-bottom: 2px; }

/* ---- Add / form view ---- */
.form-card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 20px 16px;
}
.form-card h2 { font-size: 1rem; font-weight: 700; margin-bottom: 16px; color: var(--text); }

.field { margin-bottom: 14px; }
.field label {
  display: block; font-size: .8rem; font-weight: 600;
  color: var(--text-muted); margin-bottom: 4px;
}
.field > input:not([type="checkbox"]):not([type="radio"]), .field > select {
  width: 100%; padding: 10px 12px;
  border: 1px solid var(--border2); border-radius: 8px;
  font-size: 1rem;
  background: var(--surface2); color: var(--text);
  transition: border-color .15s;
  -webkit-appearance: none;
}
.field > input:not([type="checkbox"]):not([type="radio"]):focus, .field > select:focus {
  outline: none; border-color: var(--blue);
  box-shadow: 0 0 0 3px var(--blue-bg);
}
.field select option { background: var(--surface2); color: var(--text); }

/* ---- Preview block ---- */
.preview-box {
  margin-top: 16px; padding: 14px;
  background: var(--blue-bg);
  border: 1px solid #1e3a8a; border-radius: var(--radius);
  font-size: .88rem;
}
.preview-box h3 {
  font-size: .8rem; font-weight: 700; color: var(--blue);
  margin-bottom: 10px; text-transform: uppercase; letter-spacing: .05em;
}
.preview-box .first-entry {
  color: var(--text-muted); font-style: italic; text-align: center; padding: 8px 0;
}

/* ---- Buttons ---- */
.btn {
  display: inline-flex; align-items: center; justify-content: center;
  gap: 6px; padding: 11px 20px;
  border: none; border-radius: 8px; font-size: .95rem; font-weight: 600;
  cursor: pointer; transition: opacity .15s;
  text-decoration: none;
}
.btn:disabled { opacity: .4; cursor: not-allowed; }
.btn-primary   { background: var(--blue-dk); color: #fff; width: 100%; }
.btn-primary:hover:not(:disabled) { opacity: .85; }
.btn-secondary { background: var(--surface2); color: var(--text); border: 1px solid var(--border2); }
.btn-secondary:hover { background: var(--border2); }
.btn-danger    { background: none; color: var(--red); border: 1px solid var(--red); padding: 5px 10px; font-size: .78rem; border-radius: 6px; }
.btn-danger:hover { background: var(--red-bg); }
.btn-edit      { background: none; color: var(--blue); border: 1px solid var(--blue); padding: 5px 10px; font-size: .78rem; border-radius: 6px; }
.btn-edit:hover { background: var(--blue-bg); }
.btn-sm { padding: 6px 12px; font-size: .82rem; }
.btn-full { width: 100%; }
.btn-icon { padding: 5px 7px; display:inline-flex; align-items:center; justify-content:center; }
.btn-icon svg { pointer-events: none; }

/* ---- Alert / info ---- */
.alert {
  padding: 10px 14px; border-radius: 8px; font-size: .88rem; margin-bottom: 12px;
}
.alert-error   { background: var(--red-bg);   color: var(--red);   border: 1px solid #7f1d1d; }
.alert-success { background: var(--green-bg); color: var(--green); border: 1px solid #166534; }

/* ---- Login screen ---- */
.login-wrap {
  display: flex; flex-direction: column; align-items: center; justify-content: center;
  min-height: 100vh; padding: 24px;
  background: var(--bg);
}
.login-card {
  background: var(--surface); border-radius: var(--radius);
  box-shadow: var(--shadow);
  border: 1px solid var(--border);
  padding: 32px 24px; width: 100%; max-width: 360px;
}
.login-card__logo {
  text-align: center; margin-bottom: 24px;
}
.login-card__logo svg { width: 48px; height: 48px; color: var(--blue); }
.login-card__logo h1 { font-size: 1.2rem; font-weight: 700; margin-top: 8px; color: var(--text); }
.login-card__logo p  { font-size: .82rem; color: var(--text-muted); }

/* ---- Costs form ---- */
.costs-grid {
  display: grid; grid-template-columns: 1fr 1fr; gap: 8px;
}

/* ---- Property checkboxes ---- */
.prop-checkboxes { display: flex; flex-direction: column; gap: 8px; }
.prop-checkbox-item {
  display: flex; align-items: center; gap: 10px;
  padding: 10px 12px; background: var(--surface2);
  border: 1px solid var(--border2); border-radius: 8px; cursor: pointer;
  width: 100%; text-align: left;
}
.prop-checkbox-item input[type="checkbox"] {
  width: 18px; height: 18px; accent-color: var(--blue-dk); cursor: pointer;
  flex-shrink: 0; pointer-events: none;
}
.prop-checkbox-item.is-selected {
  border-color: var(--blue);
  background: var(--blue-bg);
}
.prop-checkbox-item span { font-size: .9rem; color: var(--text); }

/* ---- User cards ---- */
.user-card {
  background: var(--surface); border: 1px solid var(--border);
  border-radius: var(--radius); padding: 14px;
  margin-bottom: 10px; display: flex; align-items: center; gap: 12px;
}
.user-card__info { flex: 1; }
.user-card__name { font-weight: 600; font-size: .95rem; color: var(--text); }
.user-card__meta { font-size: .78rem; color: var(--text-muted); margin-top: 2px; }
.user-card__actions { display: flex; gap: 6px; }
.role-badge {
  display: inline-block; padding: 2px 8px; border-radius: 4px;
  font-size: .72rem; font-weight: 600; text-transform: uppercase; letter-spacing: .05em;
}
.role-badge.admin     { background: #4c1d95; color: #c4b5fd; }
.role-badge.superuser { background: var(--blue-bg); color: var(--blue); }
.role-badge.user      { background: var(--surface2); color: var(--text-muted); }

/* ---- Note block ---- */
.note {
  font-size: .8rem; color: var(--text-muted);
  padding: 8px 12px; background: var(--surface2);
  border-radius: 6px; margin-bottom: 12px;
  border-left: 3px solid var(--border2);
}

/* ---- Spinner ---- */
.spinner {
  width: 20px; height: 20px; border: 2px solid var(--border2);
  border-top-color: var(--blue); border-radius: 50%;
  animation: spin .6s linear infinite; display: inline-block;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* ---- Loading / empty states ---- */
.state-msg {
  text-align: center; color: var(--text-muted);
  padding: 40px 16px; font-size: .9rem;
}

/* ---- Divider ---- */
.divider { border: none; border-top: 1px solid var(--border); margin: 16px 0; }

/* ---- Responsive: larger screens ---- */
@media (min-width: 540px) {
  #app { border-radius: var(--radius); height: calc(100dvh - 32px); margin-top: 16px; margin-bottom: 16px; box-shadow: var(--shadow); }
}
