/* =========================================================
1. TOKENS / VARIABLES
2. RESET / BASE
3. LAYOUT (globalny szkielet)
4. GLOBAL UI (buttons, common)
5. COMPONENTS
   - topbar
   - sidebar
   - content
   - dropdowns
6. STATES (active, open, expanded)
7. MEDIA QUERIES
   - mobile
   - desktop
8. OVERLAYS / MODALS / LIGHTBOX

   MACHINIST-TOOLKIT — THEME TOKENS / VARIABLES
   ========================================================= */

:root {
  --bg-main: #f6f7f8;
  --bg-sidebar: #f2f4f6;
  --bg-content: #f6f7f8;

  --surface: #ffffff;
  --surface-muted: #f0f1f2;
  --surface-hover: #e2e6ea;

  --text-main: #1f1f1f;
  --text-heading: #000000;
  --text-muted: #6b6b6b;

  --accent: #4b6fae;
  --accent-hover: #5f85c9;

  --border: #d0d4d9;

  --warning: #b58900;
  --error: #cc3333;
  --success: #2e7d32;

  /* unified content column tokens */
  --content-width: 100%;
  --content-padding: 16px;
}

:root[data-theme="dark"] {
  --bg-main: #1c1f23;
  --bg-sidebar: #20242a;
  --bg-content: #1c1f23;

  --surface: #262b31;
  --surface-muted: #2c3238;
  --surface-hover: #323941;

  --text-main: #d6d9dd;
  --text-heading: #ffffff;
  --text-muted: #9aa1a9;

  --accent: #6fa3e0;
  --accent-hover: #8bb6eb;

  --border: #343a40;

  --warning: #e0b454;
  --error: #e06c75;
  --success: #6fbf8f;
}

/* =========================================================
   RESET / BASE
   ========================================================= */

* {
  box-sizing: border-box;
}

html,
body {
    margin: 0;
    height: 100%;
    background: var(--bg-main);
    color: var(--text-main);
    font-family: Arial, Helvetica, sans-serif;
    font-size: 14px;
    line-height: 150%;
}

/* =========================================================
   LAYOUT (GLOBAL SHELL)
   ========================================================= */

#app {
  display: flex;
  height: calc(100vh - 56px);
}

#content {
    flex: 1;
    padding: 2rem;
    overflow-y: auto;
    background: var(--bg-content);
    position: relative;
    font-size: 15px;
    z-index: 0;
}

#content h1 {
  font-size: 1.6rem;
  margin-bottom: 1.4rem;
  color: var(--text-heading);
}

/* =========================================================
   GLOBAL UI
   ========================================================= */

.icon-button {
  width: 36px;
  height: 36px;

  display: flex;
  align-items: center;
  justify-content: center;

  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-main);

  cursor: pointer;
  font-size: 1.2rem;
}

.icon-button:hover {
  background: var(--surface-muted);
}

/* =========================================================
   COMPONENTS — TOPBAR
   ========================================================= */

#topbar {
  position: sticky;
  top: 0;
  height: 56px;
  display: flex;
  align-items: center;
  gap: 0.5rem;
  padding: 0 0.75rem;
  background: var(--bg-sidebar);
  border-bottom: 1px solid var(--border);
  z-index: 1200;
}

#sidebar-toggle {
  flex-shrink: 0;
}

#topbar-controls {
  display: flex;
  align-items: center;
  gap: 0.5rem;
}

#topbar-right {
  margin-left: auto;
  display: flex;
  align-items: center;
}

/* =========================================================
   COMPONENTS — SIDEBAR
   ========================================================= */

#sidebar {
  display: flex;
  flex-direction: column;
  width: 280px;
  background: var(--bg-sidebar);
  border-right: 1px solid var(--border);
  overflow-y: auto;
  z-index: 1000;

  /* IMPORTANT: explicit desktop default */
  transform: none;
}

#sidebar-search {
  padding: 0.75rem;
  border-bottom: 1px solid var(--border);
  background: var(--bg-sidebar);
}

.search-wrapper {
  position: relative;
}

#sidebar-search-input {
  width: 100%;
  padding: 0.45rem 2rem 0.45rem 0.6rem;
  font-size: 0.9rem;

  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-main);
}

#sidebar-search-input:focus {
  outline: none;
  border-color: var(--accent);
}

#sidebar-search-clear {
  position: absolute;
  right: 0.4rem;
  top: 50%;
  transform: translateY(-50%);

  border: none;
  background: none;
  font-size: 1rem;

  cursor: pointer;
  color: var(--text-muted);
  display: none;
}

#sidebar-search-clear:hover {
  color: var(--text-main);
}

#sidebar-content {
  flex: 1;
  overflow-y: auto;
  padding: 0.75rem 0;
}

/* =========================================================
   COMPONENTS — TOPICS / SUBTOPICS
   ========================================================= */

.sidebar-topic + .sidebar-topic {
  margin-top: 0.25rem;
}

.topic-label {
  padding: 0.5rem 0.75rem;
  font-weight: 600;
  cursor: pointer;
}

.topic-label:hover {
  background: var(--surface-hover);
}

.sidebar-topic.active > .topic-label {
    background: var(--surface-hover);
    border-left: 3px solid var(--accent);
}

.sidebar-topic .subtopics {
  display: none;
  list-style: none;
  margin: 0;
  padding: 0;
}

.sidebar-topic.expanded .subtopics {
  display: block;
  padding-left: 1.25rem;
}

.subtopics li {
  padding: 0.35rem 0.5rem;
  cursor: pointer;
}

.subtopics li:hover {
  background: var(--surface-hover);
}

.subtopics li.active {
  background: var(--surface-hover);
  font-weight: 500;
}

/* =========================================================
   COMPONENTS — DROPDOWNS (LANGUAGE)
   ========================================================= */

.language-dropdown {
  position: relative;
  margin-left: auto;
}

#language-toggle {
  height: 36px;
  width: 72px;
  padding: 0 8px;

  display: flex;
  align-items: center;
  justify-content: space-between;

  border: 1px solid var(--border);
  background: var(--surface);
  color: var(--text-main);

  cursor: pointer;
  font-size: 1.2rem;
}

#language-toggle:hover {
  background: var(--surface-muted);
}

#current-language {
  font-weight: 600;
  letter-spacing: 0.02em;
}

.language-menu {
  position: absolute;
  top: 100%;
  right: 0;
  width: 100%;
  background: var(--surface);
  border: 1px solid var(--border);
  list-style: none;
  margin: 0;
  padding: 0;
  z-index: 1000;
}

.language-menu.hidden {
  display: none;
}

.language-menu li {
  height: 32px;
  padding: 0 10px;
  display: flex;
  align-items: center;
  justify-content: space-between;
  cursor: pointer;
}

.language-menu li:hover {
  background: var(--surface-hover);
}

.language-menu li.active {
  font-weight: 600;
}

.language-menu li .lang-code {
  font-weight: 600;
  letter-spacing: 0.02em;
}

/* FIX: flag rendering must be explicit and paths must be stable */
.language-menu li .lang-flag {
  width: 20px;
  height: 14px;
  margin-left: 8px;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  flex-shrink: 0;
}

.lang-flag {
  width: 20px;
  height: 14px;
  background-repeat: no-repeat;
  background-size: cover;
  background-position: center;
  display: inline-block;
  flex-shrink: 0;
}

/* FIX: use absolute paths so flags don’t break when CSS path changes */
.lang-flag[data-flag="gb"] { background-image: url("/images/flags/gb.svg"); }
.lang-flag[data-flag="pl"] { background-image: url("/images/flags/pl.svg"); }
.lang-flag[data-flag="de"] { background-image: url("/images/flags/de.svg"); }

/* =========================================================
   OVERLAYS / DRAWER / MODALS
   ========================================================= */

#overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.4);
  display: none;
  z-index: 900;
}

#overlay.active {
  display: block;
}

/* =========================================================
   MEDIA QUERIES — RESPONSIVE
   ========================================================= */

/* FIX: mobile sidebar must be off-canvas by default, only .open shows it */
@media (max-width: 768px) {
  #sidebar {
    position: fixed;
    top: 56px;
    left: 0;
    height: calc(100vh - 56px);
    transform: translateX(-100%);
    transition: transform 0.25s cubic-bezier(0.18, 0.89, 0.32, 1.28);
    will-change: transform;
  }

  #sidebar.open {
    transform: translateX(0);
  }
}

@media (min-width: 769px) {
  #topbar #sidebar-toggle {
    display: none;
  }

  /* FIX: force desktop visible regardless of any leftovers */
  #sidebar {
    position: static;
    height: auto;
    transform: none;
  }
}

/* =========================================================
   LIGHTBOX
   ========================================================= */

.lightbox {
  position: fixed;
  inset: 0;
  background: rgba(0,0,0,0.85);
  display: flex;
  align-items: center;
  justify-content: center;
  z-index: 99999;
}

.lightbox-content {
  background: var(--surface);
  border: 1px solid var(--border);
  border-radius: 10px;
  padding: 16px;
  max-width: 92vw;
  max-height: 92vh;
  overflow: auto;
}

.lightbox-content img,
.lightbox-content svg {
  display: block;
  margin: 0 auto;
}

/* Dodatkowo: wymuś kontekst koloru dla SVG (bez wyjątków) */
.lightbox-content .diagram-svg {
  color: var(--text-main);
}

/* =========================================================
   Nieprawidlowa wartosc w kalkulatorze
   ========================================================= */

.field-error {
    font-size: 0.8rem;
    color: var(--error);
    margin-top: 2px;
}

.input-error {
    border-color: var(--error);
    background-color: rgba(204, 51, 51, 0.08);
}

/* =========================================================
   CONTENT COLUMN — unified (L1/L2/L3)
   ========================================================= */

.content-column {
  max-width: var(--content-width);
  margin: 0;
  padding-inline: var(--content-padding);
}

/* FIX: przeniesione breakpointy z content-wrapper -> content-column */
@media (min-width: 768px) {
  :root {
    --content-width: 720px;
    --content-padding: 24px;
  }

  .content-column {
    margin: 0 auto;
  }
}

@media (min-width: 1200px) {
  :root {
    --content-width: 960px;
  }
}

@media (min-width: 1600px) {
  :root {
    --content-width: 1040px;
  }
}

/* LEGACY: content-wrapper nie może kontrolować layoutu */
.content-wrapper {
  max-width: none;
  margin: 0;
  padding: 0;
}

/* =========================================================
   TOOL SECTION — L3
   ========================================================= */

.tool-section {
    margin-bottom: 3rem;
}

.tool-section .calculator {
    margin: 0; /* nie centerujemy tu */
}
