/*
  FINK invoicing app — plain/simple theme.

  This intentionally follows the STRUCTURE of fink-website's design system
  (documented in that project's notes: CSS custom properties in :root,
  Rajdhani/Exo 2/Inter font stack, Exo 2 as the Cyrillic-capable font)
  without copying its actual dark/red angular marketing look — this is a
  data-entry tool, not a marketing page, so the theme here is light,
  neutral, and plain. If FINK's real source files are made available
  later, these variables are the place to reconcile the two.
*/

:root {
  --bg: #f3f4f5;
  --panel: #ffffff;
  --panel-border: #d7dadd;
  --text: #202326;
  --text-muted: #5b6472;
  --accent: #c92127;
  --accent-hover: #a7191e;
  --accent-soft: #fbe8e8;
  --danger: #b3352c;
  --success: #2f7d4f;
  --warning: #a8711a;
  --radius: 6px;
  --font-heading: 'Exo 2', 'Rajdhani', sans-serif;
  --font-body: 'Inter', 'Exo 2', sans-serif;
}

* {
  box-sizing: border-box;
}

body {
  margin: 0;
  background-color: var(--bg);
  background-image: linear-gradient(rgba(255, 255, 255, 0.42) 1px, transparent 1px),
    linear-gradient(90deg, rgba(32, 35, 38, 0.025) 1px, transparent 1px);
  background-size: 24px 24px;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 15px;
  line-height: 1.5;
}

h1, h2, h3 {
  font-family: var(--font-heading);
  font-weight: 600;
  margin: 0 0 0.5em;
}

a {
  color: var(--accent);
}

.app-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 24px;
  background: var(--panel);
  border-top: 3px solid var(--accent);
  border-bottom: 1px solid var(--panel-border);
  box-shadow: 0 2px 10px rgba(32, 35, 38, 0.05);
}

.app-header .brand {
  display: inline-flex;
  align-items: center;
  gap: 10px;
  font-family: var(--font-heading);
  font-weight: 700;
  font-size: 1.1rem;
  color: var(--text);
  text-decoration: none;
}

.app-header .brand img {
  height: 26px;
  width: auto;
  display: block;
}

.app-header nav a {
  position: relative;
  margin-left: 20px;
  text-decoration: none;
  color: var(--text-muted);
  font-size: 0.85rem;
  font-weight: 600;
  letter-spacing: 0.02em;
  transition: color 0.15s;
}

.app-header nav a::after {
  content: '';
  position: absolute;
  left: 0;
  right: 0;
  bottom: -4px;
  height: 2px;
  background: var(--accent);
  transform: scaleX(0);
  transform-origin: left;
  transition: transform 0.2s;
}

.app-header nav a:hover {
  color: var(--accent);
}

.app-header nav a:hover::after {
  transform: scaleX(1);
}

.container {
  max-width: 960px;
  margin: 0 auto;
  padding: 24px 16px 64px;
}

.panel {
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  padding: 20px;
  margin-bottom: 20px;
  box-shadow: 0 3px 12px rgba(32, 35, 38, 0.045);
}

.menu-grid {
  display: grid;
  grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
  gap: 16px;
  margin-top: 24px;
}

/* Author display rules (button, .menu-tile, .panel ...) beat the browser's
   own [hidden] rule, so elements hidden from JS - pager buttons, the admin
   tile, disabled-module tiles - stayed visible. Make hidden always hide. */
[hidden] {
  display: none !important;
}

/* A checkbox/radio with its text in a label, left-aligned on one line
   (the generic input rule would otherwise stretch it to full width). */
.check-row {
  display: flex;
  align-items: center;
  gap: 8px;
  font-weight: normal;
  margin: 4px 0;
}
.check-row input[type="checkbox"],
.check-row input[type="radio"] {
  width: auto;
  margin: 0;
}

.menu-tile {
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 12px;
  padding: 28px 20px;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  border-left: 3px solid var(--accent);
  text-align: center;
  text-decoration: none;
  color: var(--text);
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 600;
  transition: border-color 0.15s, box-shadow 0.15s, transform 0.15s;
}

.menu-tile svg {
  width: 28px;
  height: 28px;
  stroke: var(--accent);
  fill: none;
  stroke-width: 1.6;
  stroke-linecap: round;
  stroke-linejoin: round;
}

.menu-tile:hover {
  border-color: var(--accent);
  box-shadow: 0 4px 12px rgba(32, 35, 38, 0.1), 0 8px 24px rgba(201, 33, 39, 0.18);
  transform: translateY(-2px);
}

/* A tile that opens a dropdown instead of linking straight to a page
   (e.g. "Фактури" grouping several related tiles) — the trigger is a
   <button class="menu-tile"> so it inherits the exact same look as a
   normal <a class="menu-tile">, just with the button-element resets
   below. The wrapper needs position:relative so the dropdown panel
   anchors to this one tile, not the whole grid. */
.menu-tile-dropdown {
  position: relative;
}

.menu-tile-dropdown > .menu-tile {
  width: 100%;
  height: 100%;
  border: 1px solid var(--panel-border);
  border-left: 3px solid var(--accent);
  cursor: pointer;
  /* same type as a link tile (the button element's own font is reset) */
  font-family: var(--font-heading);
  font-size: 1.05rem;
  font-weight: 600;
  color: var(--text);
}

.menu-submenu {
  position: absolute;
  top: calc(100% + 6px);
  left: 0;
  right: 0;
  background: var(--panel);
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  box-shadow: 0 8px 24px rgba(32, 35, 38, 0.18);
  overflow: hidden;
  z-index: 10;
}

.menu-submenu a {
  display: flex;
  align-items: center;
  gap: 10px;
  padding: 12px 16px;
  text-decoration: none;
  color: var(--text);
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 500;
  border-bottom: 1px solid var(--panel-border);
  transition: background 0.15s, color 0.15s;
}

.menu-submenu a:last-child {
  border-bottom: none;
}

.menu-submenu a:hover {
  background: var(--accent-soft);
  color: var(--accent);
}

.menu-submenu svg {
  width: 18px;
  height: 18px;
  stroke: var(--accent);
  fill: none;
  stroke-width: 1.8;
  stroke-linecap: round;
  stroke-linejoin: round;
  flex-shrink: 0;
}

form .field {
  margin-bottom: 14px;
}

label {
  display: block;
  font-size: 0.85rem;
  color: var(--text-muted);
  margin-bottom: 4px;
}

input, select, textarea {
  width: 100%;
  padding: 8px 10px;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  font-family: var(--font-body);
  font-size: 0.95rem;
  background: #fff;
  color: var(--text);
}

input:focus, select:focus, textarea:focus {
  outline: 2px solid rgba(201, 33, 39, 0.3);
  outline-offset: -1px;
  border-color: var(--accent);
}

button, .btn {
  display: inline-block;
  padding: 9px 18px;
  border: none;
  border-radius: var(--radius);
  background: linear-gradient(135deg, var(--accent), var(--accent-hover));
  color: #fff;
  font-family: var(--font-body);
  font-size: 0.9rem;
  font-weight: 600;
  cursor: pointer;
  text-decoration: none;
  transition: box-shadow 0.15s, transform 0.15s;
}

button:hover, .btn:hover {
  box-shadow: 0 4px 16px rgba(201, 33, 39, 0.35);
  transform: translateY(-1px);
}

button:focus-visible, a:focus-visible {
  outline: 2px solid var(--accent);
  outline-offset: 2px;
}

button.secondary, .btn.secondary {
  background: transparent;
  color: var(--accent);
  border: 1px solid var(--accent);
}

button.danger {
  background: var(--danger);
}

/* Wide tables (long client emails/addresses, many line-item columns) get
   their own horizontal scroll instead of forcing the whole page wider —
   the page body itself must never scroll sideways. Letting the table size
   to its natural content width (rather than forcing 100%) means a narrow
   viewport scrolls the table sideways instead of crushing every column
   down to one character per line. */
.table-scroll {
  overflow-x: auto;
}

table {
  width: 100%;
  min-width: fit-content;
  border-collapse: collapse;
  font-size: 0.9rem;
}

th, td {
  text-align: left;
  padding: 8px 10px;
  border-bottom: 1px solid var(--panel-border);
}

/* Only truly unbreakable content (a long email/URL with no spaces) should
   wrap inside its cell — short normal text keeps natural word wrapping,
   not this. */
td {
  overflow-wrap: break-word;
}

th {
  background: #f0f1f2;
  color: var(--text-muted);
  font-weight: 600;
  font-size: 0.8rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

tr:hover td {
  background: #fafbfc;
}

.line-items-table input, .line-items-table select {
  padding: 6px 8px;
  font-size: 0.85rem;
}

/* Phones: every table becomes a stack of cards, one per row, each value
   next to its column name. js/api.js copies each column's heading onto
   its cells as data-label (and keeps doing so when a page redraws a
   table), so no page needs its own mobile markup. A table can keep the
   desktop layout with class="no-mobile-cards". */
@media (max-width: 700px) {
  /* !important: some pages give their columns fixed widths / ellipsis for
     the desktop layout (clients.html), which must not squeeze the cards. */
  table.mobile-cards,
  table.mobile-cards tbody,
  table.mobile-cards tfoot,
  table.mobile-cards tr,
  table.mobile-cards td {
    display: block;
    width: 100% !important;
    min-width: 0 !important;
    max-width: none !important;
    overflow: visible !important;
    text-overflow: clip !important;
  }
  table.mobile-cards {
    table-layout: auto !important;
  }
  table.mobile-cards thead {
    display: none;
  }
  table.mobile-cards tr {
    border: 1px solid var(--panel-border);
    border-radius: var(--radius);
    background: var(--panel);
    margin-bottom: 10px;
    padding: 6px 12px;
  }
  table.mobile-cards tfoot tr {
    background: #f6f7f8;
  }
  table.mobile-cards td {
    display: flex !important;
    justify-content: space-between;
    align-items: center;
    gap: 12px;
    padding: 5px 0;
    border-bottom: 1px solid #eef0f2;
    text-align: right !important;
    white-space: normal !important;
  }
  table.mobile-cards td:last-child {
    border-bottom: 0;
  }
  table.mobile-cards td::before {
    content: attr(data-label);
    flex: 0 0 40%;
    text-align: left;
    color: var(--text-muted);
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
  }
  /* No heading (checkbox, action buttons, a "no rows" message): the
     content takes the whole card width. */
  table.mobile-cards td[data-label=""]::before,
  table.mobile-cards td:not([data-label])::before {
    content: none;
  }
  table.mobile-cards td[data-label=""],
  table.mobile-cards td:not([data-label]) {
    justify-content: flex-start;
    flex-wrap: wrap;
    text-align: left !important;
  }
  table.mobile-cards td:empty {
    display: none !important;
  }
  table.mobile-cards td input:not([type="checkbox"]):not([type="radio"]),
  table.mobile-cards td select {
    max-width: 60%;
  }
  table.mobile-cards tr:hover td {
    background: transparent;
  }
}

.status-badge {
  display: inline-block;
  padding: 2px 8px;
  border-radius: 999px;
  font-size: 0.75rem;
  font-weight: 600;
}

.status-draft { background: #eceff2; color: var(--text-muted); }
.status-sent { background: #dbe9f7; color: var(--accent); }
.status-paid { background: #dff2e6; color: var(--success); }
.status-unpaid { background: #fbe3e1; color: var(--danger); }
.status-overdue { background: #fbe3e1; color: var(--danger); }
.status-cancelled { background: #eceff2; color: var(--text-muted); }
.status-accepted { background: #dbe9f7; color: var(--accent); }
.status-converted { background: #dff2e6; color: var(--success); }
.status-warning { background: #f8edd9; color: var(--warning); }

.error-message {
  background: #fbe3e1;
  color: var(--danger);
  border: 1px solid #f0b8b3;
  border-radius: var(--radius);
  padding: 10px 14px;
  margin-bottom: 16px;
  font-size: 0.9rem;
}

.totals-box {
  margin-top: 16px;
  padding: 16px;
  background: #fafbfc;
  border: 1px solid var(--panel-border);
  border-radius: var(--radius);
  max-width: 320px;
  margin-left: auto;
}

.totals-box .row {
  display: flex;
  justify-content: space-between;
  padding: 3px 0;
  font-size: 0.9rem;
}

.totals-box .row.grand {
  color: var(--accent);
  font-weight: 700;
  font-size: 1.05rem;
  border-top: 1px solid var(--panel-border);
  margin-top: 6px;
  padding-top: 8px;
}

.toolbar {
  display: flex;
  justify-content: space-between;
  align-items: center;
  margin-bottom: 16px;
  gap: 12px;
  flex-wrap: wrap;
}

/* Login page only: dark background + faint logo watermark, matching
   fink.mk's look — this is the "front door" page, unlike the rest of the
   app which stays light/plain on purpose (see note at top of this file). */
.login-page {
  min-height: 100vh;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  gap: 20px;
  background: #0a0a0a;
}

.login-page .bg-watermark {
  position: fixed;
  inset: 0;
  z-index: 0;
  display: flex;
  align-items: center;
  justify-content: center;
  overflow: hidden;
  pointer-events: none;
}

.login-page .bg-watermark img {
  width: min(58vw, 780px);
  height: auto;
  opacity: 0.06;
  filter: grayscale(45%);
}

.login-logo {
  position: relative;
  z-index: 1;
  display: block;
}

.login-logo img {
  height: 42px;
  width: auto;
  display: block;
}

.login-box {
  position: relative;
  z-index: 1;
  width: 100%;
  max-width: 340px;
  padding: 32px;
  border-top: 4px solid var(--accent);
}

.modal-overlay {
  position: fixed;
  inset: 0;
  background: rgba(32, 35, 38, 0.45);
  display: flex;
  align-items: center;
  justify-content: center;
  padding: 16px;
  z-index: 100;
}

/* Author styles override the UA default [hidden]{display:none} — without
   this, setting .hidden = true in JS would leave the overlay visible
   (and blocking clicks) since .modal-overlay's own display:flex wins. */
.modal-overlay[hidden] {
  display: none;
}

.modal-box {
  background: var(--panel);
  border-radius: var(--radius);
  border-top: 4px solid var(--accent);
  padding: 24px;
  max-width: 380px;
  width: 100%;
  box-shadow: 0 12px 36px rgba(32, 35, 38, 0.25);
}

.modal-box p {
  margin: 0 0 20px;
  font-size: 0.98rem;
}

.modal-actions {
  display: flex;
  justify-content: flex-end;
  gap: 10px;
}
