/* ==========================================================================
   Digibuds | Invoicing — App Styles
   Order:
   1) Base tokens & resets
   2) Layout & generic helpers
   3) Header & navigation (incl. dropdowns + language switch)
   4) Buttons
   5) Cards
   6) Tables
   7) Badges & utilities
   8) Forms
   9) Invoice creator layout
  10) Items table (invoice/quote lines)
  11) Totals & footer actions
  12) Client search dropdown
  13) Column editor (fallback)
  14) Company list/edit additions
  15) Row actions & links
  16) Helpers
  17) Responsive
   ========================================================================== */


/* ==========================================================================
   1) Base tokens & resets
   ========================================================================== */
:root {
  --color-primary: #0d6efd;
  --color-secondary: #6c757d;
  --color-success: #198754;
  --color-danger: #dc3545;
  --color-warning: #ffc107;
  --color-info: #0dcaf0;
  --color-light: #f8f9fa;
  --color-dark: #212529;

  --font-family-sans-serif: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;

  --border-radius: 0.5rem;
  --box-shadow: 0 4px 6px -1px rgb(0 0 0 / 0.1), 0 2px 4px -2px rgb(0 0 0 / 0.1);
}

* { box-sizing: border-box; }

body {
  font-family: var(--font-family-sans-serif);
  background-color: #f0f2f5;
  color: var(--color-dark);
  margin: 0;
  line-height: 1.5;
}

.container {
  max-width: 1500px;
  margin: 0 auto;
  padding: 2rem;
}

/* Legacy/utility small bits used in a few places */
.dropdown             { position: relative; background: #fff; border: 1px solid #ddd; }
.dropdown .option     { padding: 6px 8px; cursor: pointer; }
.dropdown .option:hover { background: #f3f3f3; }
.colrow               { display: flex; gap: 8px; align-items: center; margin: 6px 0; }
.colrow .label        { min-width: 160px; }
.hint                 { color: #777; font-size: 12px; }


/* ==========================================================================
   2) Layout & generic helpers
   ========================================================================== */
.text-center { text-align: center; }
.text-right  { text-align: right; }

.font-monospace {
  font-family: SFMono-Regular, Menlo, Monaco, Consolas, "Liberation Mono", "Courier New", monospace;
}

.font-weight-500 { font-weight: 500; }


/* ==========================================================================
   3) Header & navigation (shared across all pages)
   ========================================================================== */
.main-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; }
.header-brand { display: flex; align-items: center; gap: 1rem; text-decoration: none; }
.header-logo  { height: 40px; width: auto; }
.header-actions { display: flex; align-items: center; gap: .75rem; }
.header-spacer { flex: 1; }

.main-header h1 { font-size: 1.75rem; font-weight: 600; margin: 0; }
.main-header nav { display: flex; align-items: center; gap: 1rem; }

.nav-link { color: #555; text-decoration: none; font-weight: 500; transition: color 0.2s ease; }
.nav-link:hover { color: var(--color-primary); }

/* Dropdowns used in header */
.dropdown-container,
.account-menu { position: relative; display: inline-block; }

.dropdown-menu {
  display: none;
  position: absolute;
  right: 0;
  top: calc(100% + 8px);
  background: #fff;
  min-width: 220px;
  box-shadow: 0 8px 16px rgba(0,0,0,0.1);
  border-radius: var(--border-radius);
  z-index: 100;
  border: 1px solid #ddd;
  overflow: hidden;
}
.dropdown-menu.is-active { display: block; }

.dropdown-item {
  display: block;
  padding: .75rem 1.25rem;
  color: var(--color-dark);
  text-decoration: none;
  font-weight: 500;
  font-size: .9rem;
  transition: background-color .2s ease;
}
.dropdown-item:hover,
.dropdown-item.is-active { background: var(--color-light); color: var(--color-primary); }

/* Language switcher + flag-icons */
.lang-switch { display: flex; gap: .25rem; align-items: center; }
.lang-btn {
  display: inline-flex; align-items: center; justify-content: center;
  width: 34px; height: 34px; border-radius: 8px;
  border: 1px solid #e5e7eb; background: #fff;
  text-decoration: none; font-size: 18px; line-height: 1;
}
.lang-btn:hover { background: #f9fafb; }
.lang-btn.is-active { outline: 2px solid rgba(13,110,253,.35); }
.lang-switch .fi { width: 1.2em; line-height: 1; }
.lang-switch .lang-btn { gap: .4rem; padding: .3rem .45rem; }

/* Form inside dropdowns (logout) */
.dropdown-menu form { margin: 0; }
.dropdown-menu .dropdown-item { width: 100%; text-align: left; }

/* Ghost variant for the persistent Dashboard button */
.button-ghost {
  background: #fff; color: var(--color-dark);
  border: 1px solid #e5e7eb;
}
.button-ghost:hover { background: #f9fafb; }

/* Header search */
.global-search { width: min(620px, 45vw); }
.global-search .form-control { flex: 1; min-width: 180px; }
@media (max-width: 1024px) {
  .global-search { width: min(520px, 48vw); }
}
@media (max-width: 720px) {
  .global-search { width: 100%; }
  .global-search .button { display: none; } /* keep Enter to submit on phones */
}


/* ==========================================================================
   4) Buttons
   ========================================================================== */
.button {
  display: inline-block;
  padding: 0.6rem 1.2rem;
  border: none;
  border-radius: var(--border-radius);
  text-decoration: none;
  font-weight: 600;
  cursor: pointer;
  transition: background-color 0.2s ease, transform 0.1s ease, box-shadow 0.2s ease;
}
.button:active { transform: translateY(1px); }

.button-primary {
  background-color: var(--color-primary);
  color: #fff;
  box-shadow: var(--box-shadow);
}
.button-primary:hover { background-color: #0b5ed7; }

.button-secondary {
  background-color: var(--color-light);
  color: var(--color-dark);
  border: 1px solid #ddd;
}
.button-secondary:hover { background-color: #e9ecef; }

.button-full { width: 100%; text-align: center; }

.button-link {
  background: none; border: none; padding: 0; margin: 0 0 0 .75rem;
  color: var(--color-primary); font-family: inherit; font-size: inherit; font-weight: 500;
  text-decoration: none; cursor: pointer;
}
.button-link:hover { text-decoration: underline; }


/* ==========================================================================
   5) Cards
   ========================================================================== */
.card {
  background-color: #fff;
  border-radius: var(--border-radius);
  box-shadow: var(--box-shadow);
  overflow: hidden; /* Ensures table corners are rounded */
}
.card-header {
  padding: 1rem 1.5rem;
  border-bottom: 1px solid #e9ecef;
  background: #fff;
}
.card-header h2 { margin: 0; font-size: 1.25rem; font-weight: 600; }
.card-body { padding: 0; }

.card-footer {
  padding: 1rem 1.5rem;
  background-color: #f8f9fa; /* var(--color-light) */
  border-top: 1px solid #e9ecef;
  display: flex;
  justify-content: space-between;
  align-items: center;
}


/* ==========================================================================
   6) Tables
   ========================================================================== */
table {
  width: 100%;
  border-collapse: separate; /* allow rounded th corners */
  border-spacing: 0;
}
th, td {
  padding: 1rem 1.5rem;
  text-align: left;
  border-bottom: 1px solid #e9ecef;
  vertical-align: middle;
}
thead th {
  font-weight: 600;
  color: #6c757d;
  font-size: 0.875rem;
  text-transform: uppercase;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background-color: var(--color-light); }

.empty-state { text-align: center; color: #777; padding: 3rem; }

/* keep last column visible/reserved for actions in lists */
table th:last-child,
table td:last-child {
  display: table-cell !important;
  visibility: visible !important;
  opacity: 1 !important;
  width: 180px !important;
}


/* ==========================================================================
   7) Badges & utilities
   ========================================================================== */
.badge {
  display: inline-block;
  padding: 0.3em 0.6em;
  font-size: 0.8rem;
  font-weight: 600;
  border-radius: var(--border-radius);
  text-transform: capitalize;
}
.type-invoice { color: var(--color-success); background-color: rgba(25, 135, 84, 0.1); }
.type-quote   { color: var(--color-warning); background-color: rgba(255, 193, 7, 0.1); }
.type-default { color: var(--color-info);    background-color: rgba(13, 202, 240, 0.1); }

.actions a {
  color: var(--color-primary);
  text-decoration: none;
  font-weight: 500;
  margin-right: 0.75rem;
}
.actions a:last-child { margin-right: 0; }
.actions a:hover { text-decoration: underline; }


/* ==========================================================================
   8) Forms
   ========================================================================== */
.form-group { margin-bottom: 1rem; }
.form-group:last-child { margin-bottom: 0; }
.form-group label {
  display: block;
  font-weight: 500;
  margin-bottom: 0.5rem;
  font-size: 0.875rem;
}
.form-control {
  display: block;
  width: 100%;
  padding: 0.6rem 0.8rem;
  font-size: 1rem;
  font-family: inherit;
  border: 1px solid #ced4da;
  border-radius: var(--border-radius);
  background-color: #fff;
  transition: border-color .15s ease-in-out, box-shadow .15s ease-in-out;
}
.form-control:focus {
  border-color: var(--color-primary);
  outline: 0;
  box-shadow: 0 0 0 0.25rem rgba(13, 110, 253, 0.25);
}
textarea.form-control { min-height: 80px; resize: vertical; }

.grid-2 { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem; }
.form-divider { font-size: 0.875rem; color: #6c757d; margin: 1.5rem 0; text-align: center; }

.form-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 1rem 1.5rem; }
.form-grid .span-2 { grid-column: span 2; }

.form-actions { display: flex; gap: 0.75rem; }

.form-check { display: flex; align-items: center; gap: 0.5rem; }
.form-check-input { width: 1rem; height: 1rem; }
.form-check label { margin-bottom: 0; font-weight: normal; font-size: inherit; }

.logo-preview { display: flex; align-items: center; gap: 1rem; margin-top: 0.75rem; }


/* ==========================================================================
   9) Invoice creator layout
   ========================================================================== */
.page-header { display: flex; justify-content: space-between; align-items: center; margin-bottom: 2rem; }

.invoice-creator-container {
  display: grid;
  grid-template-columns: 1fr 350px;
  gap: 2rem;
  align-items: start;
}
.main-content { display: flex; flex-direction: column; gap: 2rem; }
.sidebar { display: flex; flex-direction: column; gap: 2rem; position: sticky; top: 2rem; }


/* ==========================================================================
  10) Items table (invoice/quote lines)
   ========================================================================== */
#items { margin-bottom: 1rem; }
#items th {
  background-color: #efefef;
  border-bottom: 2px solid #e0e0e0;
  font-size: 0.8rem;
  position: sticky;
  top: 0;
  z-index: 2;
}
#items thead th:first-child { border-top-left-radius: 6px; }
#items thead th:last-child  { border-top-right-radius: 6px; }
#items td { vertical-align: middle; }
#items .form-control { min-width: 80px; }
#items input[type="number"] { text-align: right; }
.item-row td:first-child .form-control { min-width: 200px; }
.line-total { font-weight: 600; }

.remove-row-btn {
  background: transparent;
  border: none;
  color: #6c757d;
  cursor: pointer;
  padding: 0.5rem;
  border-radius: 50%;
  line-height: 0;
}
.remove-row-btn:hover { background-color: #f8d7da; color: #842029; }


/* ==========================================================================
  11) Totals & footer actions
   ========================================================================== */
.items-actions {
  display: flex;
  justify-content: space-between;
  align-items: flex-start;
  padding: 0 1.5rem 1.5rem;
}
.totals {
  width: 260px;
  font-size: 0.95rem;
  background: #f9fafb;
  border: 1px solid #e9ecef;
  border-radius: 8px;
  padding: 0.75rem 1rem;
}
.total-row { display: flex; justify-content: space-between; padding: 0.4rem 0; }
.grand-total {
  font-size: 1.15rem;
  border-top: 2px solid #dee2e6;
  margin-top: 0.5rem;
  padding-top: 0.5rem;
  font-weight: 700;
}


/* ==========================================================================
  12) Client search dropdown (generic; excludes id-based)
   ========================================================================== */
.client-search-dropdown { position: relative; }

/* Apply to any .dropdown-list EXCEPT the client search one (id="clientDropdown") */
.dropdown-list:not(#clientDropdown) {
  position: absolute;
  z-index: 1000;
  top: 100%;
  left: 0;
  right: 0;
  background: #fff;
  border: 1px solid #ced4da;
  border-top: none;
  border-radius: 0 0 var(--border-radius) var(--border-radius);
  box-shadow: 0 8px 16px rgba(0,0,0,0.1);
  max-height: 250px;
  overflow-y: auto;
  display: none;
}
.dropdown-list:not(#clientDropdown) .option {
  padding: 0.75rem 1rem;
  cursor: pointer;
  font-size: 0.9rem;
}
.dropdown-list:not(#clientDropdown) .option:hover { background-color: var(--color-light); }
.dropdown-list:not(#clientDropdown) .option:not(:last-child) { border-bottom: 1px solid #f0f2f5; }

/* Hard opt-out: inside the client search component, never show any other dropdown-list than #clientDropdown */
.client-search-dropdown > .dropdown-list:not(#clientDropdown) { display: none !important; }

/* Ensure #clientDropdown matches input width perfectly and stays above other UI */
#clientDropdown.dropdown-list {
  position: absolute;
  top: 100%;
  left: 0; right: 0;
  background: #fff;
  border: 1px solid #e5e7eb;
  border-radius: 8px;
  box-shadow: 0 8px 24px rgba(0,0,0,.08);
  max-height: 260px;
  overflow: auto;
  display: none;
  z-index: 2000;
  min-width: 100%;
}

/* Unify styling: if legacy JS inserts .option items, make them look like our .dropdown-item */
#clientDropdown .option {
  padding: .6rem .8rem;
  cursor: pointer;
  border-bottom: 1px solid #f3f4f6;
}
#clientDropdown .option:last-child { border-bottom: 0; }
#clientDropdown .option:hover,
#clientDropdown .option.active { background: #f9fafb; }
#clientDropdown .option .line-1 { font-weight: 600; }
#clientDropdown .option .line-2,
#clientDropdown .option .line-3 { font-size: .85rem; color: #6b7280; }


/* ==========================================================================
  13) Column editor (fallback)
   ========================================================================== */
.columns-editor-ui .colrow {
  display: flex; align-items: center; gap: 0.5rem;
  padding: 0.5rem; border-bottom: 1px solid #e9ecef;
}


/* ==========================================================================
  14) Company list/edit additions
   ========================================================================== */
.alert { padding: 1rem; margin-bottom: 1rem; border-radius: var(--border-radius); }
.alert-danger { background-color: #f8d7da; color: #842029; border: 1px solid #f5c2c7; }
.alert-success { background-color: #d1e7dd; color: #0f5132; border: 1px solid #badbcc; }

.company-logo-thumb {
  height: 25px;
  background-color: #fff;
  border: 0 solid #e9ecef;
  border-radius: var(--border-radius);
  padding: 4px;
  vertical-align: middle;
}


/* ==========================================================================
  15) Row actions & links
   ========================================================================== */
/* Row Actions — single row, never wrap (stable in NL/EN) */
.actions-cell{
  text-align: right;
  width: 180px; /* keep column stable */
  white-space: nowrap;
}

.actions-row{
  display: inline-flex;
  align-items: center;
  justify-content: flex-end;
  gap: 10px;
  flex-wrap: nowrap;
  white-space: nowrap;
}

/* Compact pill buttons (View/Edit) */
.action-pill{
  display: inline-flex;
  align-items: center;
  height: 30px;
  padding: 0 10px;
  border-radius: 8px;
  text-decoration: none;
  font-weight: 600;
  font-size: 0.875rem;
  color: var(--text-color-secondary);
  background: transparent;
  border: 1px solid transparent;
  line-height: 1;
}
.action-pill:hover{
  background: #eef2f7;
  border-color: #e5e7eb;
  color: var(--text-color-primary);
}

/* Delete icon button aligned inline */
.action-form{ margin: 0; }

.icon-btn{
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 30px;
  height: 30px;
  border-radius: 8px;
  border: 1px solid transparent;
  background: transparent;
  cursor: pointer;
  color: var(--text-color-muted);
  padding: 0;
  line-height: 0;
}
.icon-btn:hover{
  color: var(--color-danger, #dc3545);
  background: #fff1f1;
  border-color: #ffdada;
}

/* ==========================================================================
  15.5) Due-date badges (Invoices/Quotes lists & view)
   ========================================================================== */
.due-badge{
  display:inline-flex;
  align-items:center;
  gap:.35rem;
  border-radius:9999px;
  padding:.22rem .6rem;
  font-size:.78rem;
  font-weight:600;
  line-height:1.1;
  border:1px solid transparent;
  white-space:nowrap;
}

.due-overdue{ background:#fff1f1; color:#b12222; border-color:#ffdada; }
.due-today  { background:#fef3c7; color:#92400e; border-color:#fde68a; }
.due-soon   { background:#eef5ff; color:#2254b5; border-color:#dbe7ff; }
.due-ok     { background:#f5f5f7; color:#555; border-color:#eee; }

.due-date-muted{
  color:#6b7280;
  font-size:.85rem;
  white-space:nowrap;
}



/* ==========================================================================
  16) Helpers
   ========================================================================== */
.sr-only {
  position: absolute; width: 1px; height: 1px; padding: 0; margin: -1px;
  overflow: hidden; clip: rect(0, 0, 0, 0); white-space: nowrap; border-width: 0;
}


/* ==========================================================================
  17) Responsive
   ========================================================================== */
@media (max-width: 992px) {
  .invoice-creator-container { grid-template-columns: 1fr; }
  .sidebar { position: static; }
}

@media (max-width: 768px) {
  .form-grid { grid-template-columns: 1fr; }
  .form-grid .span-2 { grid-column: span 1; }
}
