/* Panel administracyjny. Motyw ciemny, czysty CSS, bez zaleznosci zewnetrznych. */

:root {
  --bg: #101215;
  --surface: #17191d;
  --surface-2: #1d2025;
  --surface-3: #23272d;
  --border: #2a2f36;
  --border-soft: #232830;

  --text: #d8dce1;
  --text-dim: #9aa3ad;
  --text-muted: #6f7883;

  --accent: #4a7ba7;
  --accent-hover: #5a8cba;
  --accent-soft: rgba(74, 123, 167, 0.14);

  --ok: #4f8a63;
  --warn: #b08a3c;
  --error: #a8524f;

  --radius: 4px;
  --gap: 16px;
  --sidebar-w: 216px;
  --topbar-h: 52px;

  --font: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
  --font-mono: "Cascadia Mono", Consolas, "SF Mono", Menlo, monospace;

  /* Natywne kontrolki, w tym kalendarz pola datetime-local, w wersji ciemnej */
  color-scheme: dark;
}

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

html, body {
  margin: 0;
  padding: 0;
  height: 100%;
}

body {
  background: var(--bg);
  color: var(--text);
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.45;
  -webkit-font-smoothing: antialiased;
}

h1, h2, h3 { margin: 0; font-weight: 600; }
p { margin: 0; }
a { color: var(--accent); text-decoration: none; }
a:hover { color: var(--accent-hover); }

.visually-hidden {
  position: absolute;
  width: 1px; height: 1px;
  padding: 0; margin: -1px;
  overflow: hidden;
  clip: rect(0 0 0 0);
  white-space: nowrap;
}

.icon {
  width: 16px;
  height: 16px;
  flex: 0 0 auto;
  fill: none;
  stroke: currentColor;
  stroke-width: 1.6;
  stroke-linecap: square;
  stroke-linejoin: miter;
}

.icon-lg { width: 26px; height: 26px; }

/* --- ekran logowania --------------------------------------------------- */

body.auth {
  display: flex;
  align-items: center;
  justify-content: center;
}

.auth-shell {
  width: 100%;
  padding: 24px;
  display: flex;
  justify-content: center;
}

.auth-card {
  width: 100%;
  max-width: 360px;
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  padding: 28px 26px;
}

.auth-card-narrow { max-width: 320px; text-align: center; }

.auth-head { margin-bottom: 22px; }
.auth-head .icon { color: var(--accent); margin-bottom: 10px; }

.auth-title { font-size: 17px; letter-spacing: 0.02em; }
.auth-sub { color: var(--text-muted); font-size: 12px; margin-top: 4px; }

.auth-foot {
  margin-top: 18px;
  padding-top: 14px;
  border-top: 1px solid var(--border-soft);
  color: var(--text-muted);
  font-size: 12px;
}

/* --- formularze -------------------------------------------------------- */

.form { display: flex; flex-direction: column; gap: 14px; }

.field { display: flex; flex-direction: column; gap: 6px; }

.field-label {
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
}

.input {
  width: 100%;
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 14px;
  padding: 9px 11px;
  outline: none;
  transition: border-color 0.12s ease, background 0.12s ease;
}

.input:focus {
  border-color: var(--accent);
  background: var(--surface-2);
}

.input-code {
  font-family: var(--font-mono);
  letter-spacing: 0.4em;
  text-align: center;
  font-size: 18px;
}

.alert {
  border-radius: var(--radius);
  padding: 9px 11px;
  font-size: 12px;
  margin-bottom: 14px;
  border: 1px solid transparent;
}

.alert-error {
  background: rgba(168, 82, 79, 0.12);
  border-color: rgba(168, 82, 79, 0.4);
  color: #d99b98;
}

/* --- przyciski --------------------------------------------------------- */

.btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  gap: 7px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
  color: var(--text);
  font-family: inherit;
  font-size: 13px;
  padding: 7px 13px;
  cursor: pointer;
  transition: background 0.12s ease, border-color 0.12s ease, color 0.12s ease;
}

.btn:hover { background: var(--surface-3); border-color: #363c44; }
.btn:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }
.btn[disabled] { opacity: 0.45; cursor: default; }

.btn-primary {
  background: var(--accent);
  border-color: var(--accent);
  color: #f2f6fa;
}

.btn-primary:hover { background: var(--accent-hover); border-color: var(--accent-hover); }

.btn-ghost { background: transparent; }
.btn-ghost:hover { background: var(--surface-2); }

.btn-block { width: 100%; padding: 9px 13px; }

.btn-sm { padding: 4px 9px; font-size: 12px; }

.btn[data-armed="1"] {
  border-color: rgba(168, 82, 79, 0.5);
  color: #d99b98;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 28px;
  height: 28px;
  border: 1px solid transparent;
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-dim);
  cursor: pointer;
  transition: background 0.12s ease, color 0.12s ease;
}

.icon-btn:hover { background: var(--surface-3); color: var(--text); }
.icon-btn:focus-visible { outline: 1px solid var(--accent); outline-offset: 1px; }

/* --- szkielet aplikacji ------------------------------------------------ */

.shell {
  display: grid;
  grid-template-columns: var(--sidebar-w) minmax(0, 1fr);
  min-height: 100vh;
}

.shell-main {
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.sidebar {
  background: var(--surface);
  border-right: 1px solid var(--border);
  display: flex;
  flex-direction: column;
  position: sticky;
  top: 0;
  height: 100vh;
}

.sidebar-brand {
  display: flex;
  align-items: center;
  gap: 9px;
  height: var(--topbar-h);
  padding: 0 16px;
  border-bottom: 1px solid var(--border);
  font-size: 12px;
  font-weight: 600;
  letter-spacing: 0.18em;
  color: var(--text-dim);
}

.sidebar-brand .icon { color: var(--accent); }

.sidebar-nav {
  display: flex;
  flex-direction: column;
  padding: 10px 8px;
  gap: 2px;
  flex: 1 1 auto;
  overflow-y: auto;
}

.nav-item {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 8px 10px;
  border-radius: var(--radius);
  color: var(--text-dim);
  font-size: 13px;
  border-left: 2px solid transparent;
}

.nav-item:hover { background: var(--surface-2); color: var(--text); }

.nav-item.is-active {
  background: var(--accent-soft);
  border-left-color: var(--accent);
  color: var(--text);
}

.sidebar-foot {
  padding: 12px 16px;
  border-top: 1px solid var(--border);
  font-size: 11px;
  color: var(--text-muted);
}

.status-line { display: flex; align-items: center; gap: 8px; }

.dot {
  width: 7px;
  height: 7px;
  border-radius: 50%;
  background: var(--text-muted);
  flex: 0 0 auto;
}

.dot[data-state="ok"] { background: var(--ok); }
.dot[data-state="error"] { background: var(--error); }
.dot[data-state="warn"] { background: var(--warn); }

/* --- pasek gorny ------------------------------------------------------- */

.topbar {
  display: flex;
  align-items: center;
  gap: 12px;
  height: var(--topbar-h);
  padding: 0 16px;
  background: var(--surface);
  border-bottom: 1px solid var(--border);
  position: sticky;
  top: 0;
  z-index: 20;
}

.topbar-title {
  font-size: 14px;
  font-weight: 600;
  letter-spacing: 0.01em;
}

.topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 10px;
}

.clock {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
}

.user-chip {
  font-size: 12px;
  color: var(--text-dim);
  padding: 4px 9px;
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.logout-form { margin: 0; }

#menu-toggle { display: none; }

/* --- siatka tresci ----------------------------------------------------- */

.content { padding: var(--gap); flex: 1 1 auto; }

.grid {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: var(--gap);
  align-items: start;
}

.grid-col { display: flex; flex-direction: column; gap: var(--gap); min-width: 0; }
.grid-col-full { grid-column: 1 / -1; }

/* --- karty ------------------------------------------------------------- */

.card {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  display: flex;
  flex-direction: column;
  min-width: 0;
}

.card-head {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 10px 14px;
  border-bottom: 1px solid var(--border);
  background: var(--surface-2);
  border-radius: var(--radius) var(--radius) 0 0;
}

.card-title {
  font-size: 12px;
  text-transform: uppercase;
  letter-spacing: 0.09em;
  color: var(--text-dim);
}

.card-actions {
  margin-left: auto;
  display: flex;
  align-items: center;
  gap: 8px;
}

.card-body { padding: 12px 14px; min-width: 0; }

.card.is-loading { opacity: 0.6; }
.card.is-error { border-color: rgba(168, 82, 79, 0.45); }

.stamp {
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

.badge {
  min-width: 20px;
  text-align: center;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 2px 6px;
  border-radius: var(--radius);
  background: var(--accent-soft);
  color: var(--accent-hover);
  border: 1px solid rgba(74, 123, 167, 0.3);
}

.badge-muted {
  background: var(--surface-3);
  color: var(--text-muted);
  border-color: var(--border);
}

.empty {
  color: var(--text-muted);
  font-size: 12px;
  padding: 8px 0;
  text-align: left;
}

/* --- lista procesow ---------------------------------------------------- */

.process-list, .checklist, .agenda {
  list-style: none;
  margin: 0;
  padding: 0;
  display: flex;
  flex-direction: column;
  gap: 8px;
}

.process {
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 9px 11px;
}

.process-head {
  display: flex;
  align-items: center;
  gap: 8px;
  margin-bottom: 7px;
}

.process-name { font-size: 13px; }

.process-meta {
  margin-left: auto;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
  display: flex;
  align-items: center;
  gap: 8px;
}

.process-sub {
  display: block;
  font-family: var(--font-mono);
  font-size: 11px;
  color: var(--text-muted);
}

/* --- panel skryptow ---------------------------------------------------- */

.script-grid {
  display: grid;
  grid-template-columns: repeat(auto-fill, minmax(180px, 1fr));
  gap: 10px;
}

.script {
  display: flex;
  flex-direction: column;
  gap: 8px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface-2);
  padding: 11px;
}

.script-name { font-size: 13px; }
.script-desc { font-size: 11px; color: var(--text-muted); flex: 1 1 auto; }

/* --- tabele ------------------------------------------------------------ */

.table-wrap { overflow-x: auto; }

.table {
  width: 100%;
  border-collapse: collapse;
  font-size: 13px;
}

.table th {
  text-align: left;
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.07em;
  color: var(--text-muted);
  font-weight: 500;
  padding: 6px 10px;
  border-bottom: 1px solid var(--border);
  white-space: nowrap;
}

.table td {
  padding: 8px 10px;
  border-bottom: 1px solid var(--border-soft);
  vertical-align: middle;
}

.table tbody tr:last-child td { border-bottom: none; }
.table tbody tr:hover { background: var(--surface-2); }

.table-log td:nth-child(1),
.table-log td:nth-child(2) {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-dim);
  white-space: nowrap;
}

.col-action { width: 96px; }

.cell-sender { color: var(--text-dim); white-space: nowrap; }
.cell-body { color: var(--text); }
.row-unread .cell-sender { color: var(--text); font-weight: 600; }

.col-time { width: 62px; }
.col-account { width: 180px; }

.cell-time {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--text-muted);
  white-space: nowrap;
}

.cell-actions { white-space: nowrap; }
.cell-actions .btn + .btn { margin-left: 6px; }

.msg-subject { display: block; }

.msg-snippet {
  display: block;
  font-size: 12px;
  color: var(--text-muted);
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  max-width: 460px;
}

.row-unread .msg-subject { font-weight: 600; }

.day-row td {
  background: var(--surface-2);
  font-size: 11px;
  text-transform: uppercase;
  letter-spacing: 0.08em;
  color: var(--text-muted);
  padding: 5px 10px;
}

.day-row:hover td { background: var(--surface-2); }

.chip {
  display: inline-block;
  max-width: 100%;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
  vertical-align: bottom;
  font-family: var(--font-mono);
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  border: 1px solid var(--border);
  background: var(--surface-2);
  color: var(--text-dim);
}

.tabs {
  display: flex;
  flex-wrap: wrap;
  gap: 6px;
  margin-bottom: 10px;
}

.tab {
  border: 1px solid var(--border);
  border-radius: var(--radius);
  background: transparent;
  color: var(--text-dim);
  font-family: inherit;
  font-size: 12px;
  padding: 4px 10px;
  cursor: pointer;
  max-width: 220px;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.tab:hover { background: var(--surface-2); color: var(--text); }

.tab.is-active {
  background: var(--accent-soft);
  border-color: var(--accent);
  color: var(--text);
}

.tag {
  display: inline-block;
  font-size: 11px;
  padding: 1px 7px;
  border-radius: 10px;
  border: 1px solid var(--border);
  color: var(--text-dim);
  background: var(--surface-2);
  white-space: nowrap;
}

.tag[data-status="ok"] { color: #7fb894; border-color: rgba(79, 138, 99, 0.4); background: rgba(79, 138, 99, 0.1); }
.tag[data-status="warn"] { color: #d2b071; border-color: rgba(176, 138, 60, 0.4); background: rgba(176, 138, 60, 0.1); }
.tag[data-status="error"] { color: #d99b98; border-color: rgba(168, 82, 79, 0.4); background: rgba(168, 82, 79, 0.1); }
.tag[data-status="running"] { color: var(--accent-hover); border-color: rgba(74, 123, 167, 0.4); background: var(--accent-soft); }

.filter .input,
.filter input[type="search"] {
  background: var(--bg);
  border: 1px solid var(--border);
  border-radius: var(--radius);
  color: var(--text);
  font-family: inherit;
  font-size: 12px;
  padding: 4px 8px;
  width: 130px;
  outline: none;
}

.filter input[type="search"]:focus { border-color: var(--accent); }

/* --- lista zadan ------------------------------------------------------- */

.checklist li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 9px;
  border: 1px solid var(--border-soft);
  border-radius: var(--radius);
  background: var(--surface-2);
}

.checklist input[type="checkbox"] {
  appearance: none;
  width: 14px;
  height: 14px;
  border: 1px solid var(--border);
  border-radius: 2px;
  background: var(--bg);
  cursor: pointer;
  position: relative;
  flex: 0 0 auto;
}

.checklist input[type="checkbox"]:checked {
  background: var(--accent);
  border-color: var(--accent);
}

.checklist input[type="checkbox"]:checked::after {
  content: "";
  position: absolute;
  left: 4px;
  top: 1px;
  width: 4px;
  height: 8px;
  border: solid #f2f6fa;
  border-width: 0 2px 2px 0;
  transform: rotate(45deg);
}

.checklist .is-done { color: var(--text-muted); text-decoration: line-through; }

.task-label {
  flex: 1 1 auto;
  min-width: 0;
  overflow-wrap: anywhere;
}

.task-form {
  display: flex;
  gap: 8px;
  align-items: flex-end;
  padding-bottom: 12px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border-soft);
}

.task-form .field { flex: 1 1 auto; min-width: 0; }
.task-form .btn { flex: 0 0 auto; }

.checklist .icon-btn {
  width: auto;
  padding: 0 6px;
  font-size: 11px;
  color: var(--text-muted);
}

.checklist .icon-btn:hover { color: #d99b98; background: var(--surface-3); }
.checklist li.task-done { opacity: 0.7; }

/* --- kalendarz --------------------------------------------------------- */

.event-form {
  display: flex;
  flex-direction: column;
  gap: 9px;
  padding-bottom: 12px;
  margin-bottom: 10px;
  border-bottom: 1px solid var(--border-soft);
}

.field-row {
  display: grid;
  grid-template-columns: repeat(2, minmax(0, 1fr));
  gap: 9px;
}

.input-sm { padding: 6px 9px; font-size: 13px; }

.event-form .btn { align-self: flex-start; }

.agenda li {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 7px 0;
  border-bottom: 1px solid var(--border-soft);
  font-size: 13px;
}

.agenda li:last-child { border-bottom: none; }

.agenda .time {
  font-family: var(--font-mono);
  font-size: 12px;
  color: var(--accent-hover);
  flex: 0 0 auto;
  white-space: nowrap;
}

.agenda-title {
  flex: 1 1 auto;
  min-width: 0;
  overflow: hidden;
  text-overflow: ellipsis;
  white-space: nowrap;
}

.agenda-item .btn { flex: 0 0 auto; }

/* --- powiadomienie ----------------------------------------------------- */

.toast {
  position: fixed;
  right: 16px;
  bottom: 16px;
  z-index: 60;
  max-width: 320px;
  background: var(--surface-3);
  border: 1px solid var(--border);
  border-left: 2px solid var(--accent);
  border-radius: var(--radius);
  padding: 10px 13px;
  font-size: 12px;
  color: var(--text);
}

.toast[data-kind="error"] { border-left-color: var(--error); }
.toast[data-kind="ok"] { border-left-color: var(--ok); }

/* --- responsywnosc ----------------------------------------------------- */

@media (max-width: 560px) {
  /* Pola daty nie mieszcza sie obok siebie na waskim ekranie */
  .field-row { grid-template-columns: minmax(0, 1fr); }
}

@media (max-width: 1000px) {
  .grid { grid-template-columns: minmax(0, 1fr); }
  .grid-col-full { grid-column: auto; }
}

@media (max-width: 760px) {
  .shell { grid-template-columns: minmax(0, 1fr); }

  .sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: var(--sidebar-w);
    z-index: 40;
    transform: translateX(-100%);
    transition: transform 0.15s ease;
  }

  .sidebar.is-open { transform: translateX(0); }

  #menu-toggle { display: inline-flex; }

  .clock, .user-chip { display: none; }

  .content { padding: 12px; }
}

@media (prefers-reduced-motion: reduce) {
  * { transition: none !important; }
}
