:root {
  --bg: #f4f5f7;
  --panel: #ffffff;
  --border: #d9dce1;
  --text: #1f2430;
  --muted: #6b7280;
  --accent: #2563eb;
  --accent-dark: #1d4ed8;
  --danger: #dc2626;
  --positive: #16a34a;
  --negative: #dc2626;
  font-family: -apple-system, Segoe UI, Roboto, Arial, sans-serif;
}

* { box-sizing: border-box; }

body {
  margin: 0;
  background: var(--bg);
  color: var(--text);
  font-size: 14px;
}

.hidden { display: none !important; }
.muted { color: var(--muted); font-size: 12.5px; }
.error-msg { color: var(--danger); font-size: 13px; min-height: 1.2em; }

/* Login */
#login-screen {
  min-height: 100vh;
  display: flex;
  align-items: center;
  justify-content: center;
}
.login-box {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 32px;
  width: 320px;
  text-align: center;
}
.login-box h1 { margin: 0 0 4px; font-size: 20px; }
.login-box p { margin: 0 0 16px; color: var(--muted); }
.login-box input {
  width: 100%;
  padding: 10px;
  margin-bottom: 12px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

button {
  padding: 8px 14px;
  border-radius: 6px;
  border: none;
  background: var(--accent);
  color: white;
  cursor: pointer;
  font-size: 13px;
}
button:hover { background: var(--accent-dark); }
button.secondary {
  background: transparent;
  color: var(--text);
  border: 1px solid var(--border);
}
button.secondary:hover { background: #eceef1; }
button.small { padding: 3px 8px; font-size: 12px; }

/* Topbar */
.topbar {
  background: var(--panel);
  border-bottom: 1px solid var(--border);
  padding: 12px 20px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  flex-wrap: wrap;
  gap: 10px;
}
.topbar h1 { font-size: 17px; margin: 0; }
.topbar-controls { display: flex; align-items: center; gap: 10px; flex-wrap: wrap; }
.topbar-controls input[type=month] {
  padding: 7px 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
}

main { padding: 20px; max-width: 1500px; margin: 0 auto; }

.table-wrap {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  overflow-x: auto;
}

table { width: 100%; border-collapse: collapse; font-size: 12.5px; min-width: 1200px; }
th, td { padding: 6px 8px; border-bottom: 1px solid var(--border); text-align: left; white-space: nowrap; }
thead th { background: #eef1f5; position: sticky; top: 0; font-size: 12px; }
tbody tr:hover { background: #f9fafb; }
tfoot td { font-weight: 600; background: #eef1f5; }

td.num, th.num { text-align: right; }
td input, td select, td textarea {
  width: 100%;
  border: 1px solid transparent;
  background: transparent;
  font-size: 12.5px;
  padding: 3px 4px;
  border-radius: 4px;
  font-family: inherit;
}
td input:hover, td select:hover, td textarea:hover { border-color: var(--border); }
td input:focus, td select:focus, td textarea:focus { border-color: var(--accent); background: white; outline: none; }
td.uwagi-cell textarea { resize: vertical; min-height: 28px; white-space: normal; }

.marza-pos { color: var(--positive); font-weight: 600; }
.marza-neg { color: var(--negative); font-weight: 600; }

.badge {
  display: inline-block;
  background: #e0e7ff;
  color: #3730a3;
  border-radius: 4px;
  padding: 1px 6px;
  font-size: 11px;
  margin-right: 3px;
  white-space: nowrap;
}
.link-btn {
  background: none;
  border: 1px dashed var(--border);
  color: var(--muted);
  padding: 2px 6px;
  font-size: 11px;
}
.link-btn:hover { background: #eceef1; }

/* Summary */
#summary-panel {
  background: var(--panel);
  border: 1px solid var(--border);
  border-radius: 8px;
  margin-top: 16px;
  padding: 16px 20px;
}
#summary-panel h2 { font-size: 15px; margin: 0 0 12px; }
.summary-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 10px 20px;
  margin-bottom: 16px;
}
.summary-item { border-bottom: 1px dotted var(--border); padding-bottom: 6px; }
.summary-item .label { color: var(--muted); font-size: 12px; }
.summary-item .value { font-size: 15px; font-weight: 600; }
.summary-item .value.warn { color: #b45309; }

.notes-box { display: flex; flex-direction: column; gap: 8px; }
.notes-box textarea {
  width: 100%;
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  font-family: inherit;
  font-size: 13px;
}
.notes-box button { align-self: flex-start; }

/* Modal */
.modal-overlay {
  position: fixed; inset: 0;
  background: rgba(0,0,0,0.4);
  display: flex; align-items: center; justify-content: center;
  z-index: 100;
}
.modal {
  background: var(--panel);
  border-radius: 10px;
  padding: 20px;
  width: 480px;
  max-width: 92vw;
  max-height: 85vh;
  overflow-y: auto;
}
.modal h2 { margin-top: 0; font-size: 16px; }
.modal input[type=text] {
  width: 100%;
  padding: 8px;
  border: 1px solid var(--border);
  border-radius: 6px;
  margin-bottom: 10px;
}
.link-results { display: flex; flex-direction: column; gap: 6px; max-height: 320px; overflow-y: auto; margin-bottom: 12px; }
.link-result-row {
  border: 1px solid var(--border);
  border-radius: 6px;
  padding: 8px;
  display: flex;
  justify-content: space-between;
  align-items: center;
  gap: 8px;
  font-size: 12.5px;
}
.link-result-row .meta { flex: 1; }
.link-result-row .actions { display: flex; gap: 4px; }

.rates-form { display: flex; gap: 8px; margin: 12px 0; flex-wrap: wrap; }
.rates-form input { padding: 7px; border: 1px solid var(--border); border-radius: 6px; }
.rates-form input#rate-name { flex: 1; min-width: 140px; }
.rates-form input#rate-percent { width: 70px; }
.rates-form input#rate-note { flex: 1; min-width: 120px; }

#rates-table { width: 100%; border-collapse: collapse; margin-top: 8px; font-size: 12.5px; }
#rates-table th, #rates-table td { padding: 6px; border-bottom: 1px solid var(--border); text-align: left; }
