/* === Base Reset & Fonts === */
@import url('https://fonts.googleapis.com/css2?family=Google+Sans:wght@400;500;700&display=swap');

* {
  box-sizing: border-box; /* Include padding/borders in width */
}

body {
  margin: 0;
  font-family: 'Google Sans', Arial, sans-serif;
  background: #f3f6f9;
  font-size: 1rem;
  color: #1e1e1e;
  height: 100vh;
  width: 100%;
  overflow-x: hidden; /* No horizontal scrolling */
  overscroll-behavior: none; /* Disable mobile pull-to-refresh */
}

body.hidden-until-validated {
  display: none;
}

body.drawer-open {
  overflow: hidden; /* Lock all scrolling when drawer is open */
}

/* === Drawer === */
.drawer {
  position: fixed;
  top: 0;
  left: 0;
  width: 80vw;
  max-width: 420px;
  height: 100vh;
  max-height: 100vh;
  background: #fff;
  border-right: 1px solid #d8dde6;
  border-radius: 0 12px 12px 0;
  box-shadow: 0 8px 24px rgba(0, 0, 0, 0.2);
  z-index: 1000;
  transform: translateX(-100%);
  transition: transform 0.3s ease;
  overflow-x: hidden; /* No horizontal scrolling */
  overflow-y: auto; /* Allow vertical scrolling if content overflows */
}

.drawer.open {
  transform: translateX(0);
}

.drawer-overlay {
  position: fixed;
  inset: 0;
  background: rgba(0, 0, 0, 0.35);
  opacity: 0;
  pointer-events: none;
  transition: opacity 0.2s ease;
  z-index: 999;
}

body.drawer-open .drawer-overlay {
  opacity: 1;
  pointer-events: auto;
}

.drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #e7e9ee;
}

.drawer__title {
  font-size: 1rem;
  margin: 0;
  color: #000;
}

.drawer__close {
  border: none;
  background: transparent;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  padding: 0.25rem 0.5rem;
  color: #03363d;
}

.drawer__content {
  padding: 0.5rem 0.75rem;
}

.drawer-menu {
  list-style: none;
  margin: 0;
  padding: 0;
}

.drawer-menu li {
  margin: 0.375rem 0;
}

.drawer-menu a,
.drawer-menu button {
  display: block;
  max-width: calc(100% - 1.5rem); /* Account for 0.75rem padding on each side */
  padding: 0.5rem;
  border-radius: 0.5rem;
  border: 1px solid #e7e9ee;
  background: #fff;
  color: #1e1e1e;
  text-decoration: none;
  font-weight: 500;
  font-size: 0.9rem;
  cursor: pointer;
  text-align: left;
  overflow-x: hidden;
}

.drawer-menu a:hover,
.drawer-menu button:hover {
  background: #f4f6f9;
}

@media (max-width: 768px) {
  .drawer {
    width: 80vw;
    max-width: 320px; /* Smaller for mobile */
    overflow-x: hidden;
    overflow-y: auto; /* Allow vertical scrolling if needed */
  }
  body.drawer-open .main {
    overflow: hidden; /* Lock main content */
  }
  body {
    width: 100%;
    overflow-x: hidden;
  }
}

/* === Login Page === */
.login-page {
  display: flex;
  justify-content: center;
  align-items: center;
  height: 100vh;
  background: #f3f6f9;
  overflow-x: hidden;
}

.login-box {
  width: 90%;
  max-width: 320px;
  padding: 1.5rem;
  border-radius: 0.5rem;
  background: #fff;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.1);
}

/* === Forms & Inputs === */
input[type="text"],
input[type="email"],
input[type="password"],
select {
  width: 100%;
  height: 2.25rem;
  padding: 0 0.75rem;
  font-size: 0.9rem;
  color: #333;
  background: #f9fafb;
  border: 1px solid #d8dde6;
  border-radius: 0.25rem;
  transition: border-color 0.2s ease, box-shadow 0.2s ease;
}

input:focus,
select:focus {
  border-color: #009688;
  box-shadow: 0 0 0 3px rgba(0, 150, 136, 0.2);
  outline: none;
}

select {
  appearance: none;
  background-image: url("data:image/svg+xml;utf8,<svg fill='%23333' height='16' viewBox='0 0 24 24' width='16' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/></svg>");
  background-repeat: no-repeat;
  background-position: right 0.75rem center;
  background-size: 1rem;
}

.form-ui {
  display: flex;
  flex-wrap: wrap;
  gap: 0.75rem;
  padding: 1rem;
  background: #fff;
  border: 1px solid #d8dde6;
  border-radius: 0.5rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
}

/* === Buttons === */
button,
.form-ui .btn-primary,
.table-ui button {
  height: 2.25rem;
  padding: 0 1rem;
  border: none;
  border-radius: 0.25rem;
  background: #009688;
  color: white;
  font-size: 0.9rem;
  cursor: pointer;
  transition: background 0.2s ease;
}

button:hover,
.form-ui .btn-primary:hover,
.table-ui button:hover {
  background: #00796b;
}

.special-logout {
  background: linear-gradient(135deg, #d83a00, #ff5f2e);
  padding: 0.5rem;
  max-width: calc(100% - 1.5rem); /* Fit within drawer padding */
  border-radius: 1rem;
  box-shadow: 0 4px 8px rgba(216, 58, 0, 0.3);
  transition: background 0.3s ease, transform 0.2s ease;
}

.special-logout:hover {
  background: linear-gradient(135deg, #b32e00, #e64b1a);
  transform: translateY(-2px);
  box-shadow: 0 6px 12px rgba(216, 58, 0, 0.4);
}

.special-logout:active {
  transform: translateY(0);
  box-shadow: 0 3px 6px rgba(216, 58, 0, 0.3);
}

/* === Tables (scrollable) === */
.table-wrapper {
  margin-top: 1rem;
  background: #fff;
  border: 1px solid #d8dde6;
  border-radius: 0.5rem;
  padding: 1rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);

  /* key changes */
  overflow-x: auto;              /* was hidden → allow horizontal scroll */
  overflow-y: visible;           /* keep selects/menus visible */
  -webkit-overflow-scrolling: touch;
  position: relative;
}

.table-ui {
  width: 100%;
  min-width: 980px;              /* force scroll if columns don’t fit */
  border-collapse: collapse;
  font-size: 0.9rem;
  position: relative;

  /* let columns size naturally; avoids over-squashing */
  table-layout: auto;            /* was fixed */
}

.table-ui thead {
  background: #f4f6f9;
}

.table-ui thead th {
  text-align: left;
  padding: 0.75rem;
  font-weight: 600;
  color: #333;
  border-bottom: 1px solid #d8dde6;
  white-space: nowrap;           /* prevent header wrapping */
}

.table-ui tbody tr:nth-child(odd) { background: #fafafa; }
.table-ui tbody tr:hover       { background: #f0f7f7; }

.table-ui td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid #e4e7eb;
  min-width: 0;
  position: relative;
  white-space: nowrap;           /* avoid cramped multi-line cells */
}

/* Allow the "Líneas" column to wrap if needed; others stay single-line */
.table-ui td:nth-child(2) {
  min-width: 220px;              /* room for long summaries/links */
  white-space: normal;           /* allow wrapping only here */
}

/* Keep selects usable in narrow cells */
.table-ui select {
  height: 2rem;
  padding: 0 1.5rem 0 0.5rem;
  font-size: 0.85rem;
  background-image: url("data:image/svg+xml;utf8,<svg fill='%23333' height='14' viewBox='0 0 24 24' width='14' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/></svg>");
  background-position: right 0.5rem center;
  background-size: 0.875rem;
  position: relative;
  width: 100%;
  display: block;
  z-index: 1000;                 /* dropdown above scroller */
  scroll-margin-top: 4rem;
}

/* Optional: subtle horizontal scrollbar styling */
.table-wrapper::-webkit-scrollbar {
  height: 10px;
}
.table-wrapper::-webkit-scrollbar-thumb {
  background: #cfd6df;
  border-radius: 6px;
}
.table-wrapper::-webkit-scrollbar-track {
  background: #f4f6f9;
}

/* === Main Layout === */
.main {
  margin-left: 0;
  background: #f5f6f7;
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
  overflow-y: auto; /* Allow vertical scrolling when drawer is closed */
  scroll-padding-top: 4rem; /* Ensure select is in view when focused */
}

.main-panel,
.main-panel-detail {
  background: #fff;
  border-radius: 0.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  padding: 1.5rem;
  margin: 1.5rem;
  max-width: 100%;
  overflow-x: hidden;
  position: relative; /* Stable context for dropdown */
  overflow-y: visible; /* Prevent clipping dropdown */
}

.main-panel-detail {
  flex: 1; /* Grow to fill remaining space */
}

.main-panel h2,
.main-panel-detail h2 {
  margin-top: 0;
  font-size: 1.25rem;
  color: #1e1e1e;
}

.main-panel h3 {
  margin-top: 1rem;
  font-size: 1rem;
  color: #1e1e1e;
}

.main-panel pre {
  background: #f4f6f9;
  padding: 0.75rem;
  border-radius: 0.25rem;
  border: 1px solid #d8dde6;
  overflow-x: auto;
}

/* === Header === */
.main-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  background: #03363d;
  padding: 0.75rem 1rem;
  border-bottom: 1px solid #d8dde6;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  overflow-x: hidden;
}

.main-header h1 {
  font-size: 1.25rem;
  color: #fff;
  margin: 0;
}

.main-header .actions {
  display: flex;
  gap: 0.5rem;
}

.main-header .actions button {
  padding: 0.5rem 0.75rem;
  background: #fff;
  color: #000;
  border: none;
  border-radius: 0.25rem;
  cursor: pointer;
  font-size: 0.9rem;
}

.main-header .actions button:hover {
  background: #005fb2;
}

.header-left {
  display: flex;
  align-items: center;
  gap: 0.75rem;
}

.header-logo {
  height: 2rem;
  width: auto;
}

@media (max-width: 768px) {
  .main-header {
    gap: 0.75rem;
    overflow-x: hidden;
  }
  .drawer-toggle {
    order: -1;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    color: #fff;
    font-size: 1.25rem;
    padding: 0.375rem 0.5rem;
    border: none;
    background: transparent;
    cursor: pointer;
  }
  .header-logo {
    height: 1.5rem;
  }
}

/* === Sidebar & Side Panel === */
.sidebar,
.side-panel {
  background: #fff;
  padding: 1rem;
  border-radius: 0.5rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  overflow-x: hidden;
}

.sidebar {
  width: 90%;
  max-width: 20rem;
  border-right: 1px solid #d8dde6;
}

.side-panel {
  width: 20%;
  max-width: 20rem;
}

.sidebar h3,
.side-panel h3 {
  margin-top: 0;
  font-size: 1rem;
  color: #0070d2;
}

.sidebar ul,
.side-panel ul {
  list-style: none;
  padding: 0;
  margin: 0;
}

.sidebar li,
.side-panel li {
  padding: 0.625rem;
  margin: 0.25rem 0;
  cursor: pointer;
  border-radius: 0.25rem;
}

.sidebar li:hover,
.side-panel li:hover {
  background: #f4f6f9;
}

.nav-back {
  display: inline-block;
  margin-bottom: 1rem;
  text-decoration: none;
  color: #0070d2;
  font-size: 0.9rem;
}

.nav-back:hover {
  text-decoration: underline;
}

/* === Tables === */
.table-wrapper {
  margin-top: 1rem;
  background: #fff;
  border: 1px solid #d8dde6;
  border-radius: 0.5rem;
  padding: 0rem;
  box-shadow: 0 2px 4px rgba(0, 0, 0, 0.05);
  overflow-x: hidden;
  overflow-y: visible; /* Allow dropdown to render outside wrapper */
  position: relative; /* Stable positioning context */
}

.table-ui {
  width: 100%;
  border-collapse: collapse;
  font-size: 0.9rem;
  position: relative;
  table-layout: fixed; /* Stabilize column widths */
}

.table-ui thead {
  background: #f4f6f9;
}

.table-ui thead th {
  text-align: left;
  padding: 0.75rem;
  font-weight: 600;
  color: #333;
  border-bottom: 1px solid #d8dde6;
}

.table-ui tbody tr:nth-child(odd) {
  background: #fafafa;
}

.table-ui tbody tr:hover {
  background: #f0f7f7;
}

.table-ui td {
  padding: 0.625rem 0.75rem;
  border-bottom: 1px solid #e4e7eb;
  min-width: 0;
  position: relative;
}

.table-ui td:nth-child(2) {
  min-width: 140px; /* Increased for select stability */
  min-height: 3rem; /* More room for dropdown */
}

.table-ui select {
  height: 2rem;
  padding: 0 1.5rem 0 0.5rem;
  font-size: 0.85rem;
  background-image: url("data:image/svg+xml;utf8,<svg fill='%23333' height='14' viewBox='0 0 24 24' width='14' xmlns='http://www.w3.org/2000/svg'><path d='M7 10l5 5 5-5z'/></svg>");
  background-position: right 0.5rem center;
  background-size: 0.875rem;
  position: relative;
  width: 100%;
  display: block;
  z-index: 1000; /* High z-index to prioritize dropdown */
  scroll-margin-top: 4rem; /* Ensure select is in view when focused */
}

/* === Main Layout === */
.main {
  margin-left: 0;
  background: #f5f6f7;
  min-height: 100vh;
  width: 100%;
  overflow-x: hidden;
  overflow-y: auto; /* Allow vertical scrolling when drawer is closed */
  scroll-padding-top: 4rem; /* Ensure select is in view when focused */
}

.main-panel,
.main-panel-detail {
  background: #fff;
  border-radius: 0.5rem;
  box-shadow: 0 4px 12px rgba(0, 0, 0, 0.05);
  padding: 1.5rem;
  margin: 1.5rem;
  max-width: 100%;
  overflow-x: hidden;
  position: relative; /* Stable context for dropdown */
  overflow-y: visible; /* Prevent clipping dropdown */
}

.main-panel-detail {
  flex: 1; /* Grow to fill remaining space */
}

.main-panel h2,
.main-panel-detail h2 {
  margin-top: 0;
  font-size: 1.25rem;
  color: #1e1e1e;
}

.main-panel h3 {
  margin-top: 1rem;
  font-size: 1rem;
  color: #1e1e1e;
}

.main-panel pre {
  background: #f4f6f9;
  padding: 0.75rem;
  border-radius: 0.25rem;
  border: 1px solid #d8dde6;
  overflow-x: auto;
}

/* === Detail Container === */
.detail-container {
  display: flex;
  height: calc(100vh - 3rem); /* Adjust for header */
  overflow-x: hidden;
  overflow-y: visible; /* Allow dropdown to render fully */
}

@media (max-width: 768px) {
  .detail-container {
    flex-direction: column; /* Stack vertically on mobile */
    overflow-y: visible; /* Allow dropdown to render fully */
  }
  .side-panel {
    width: 100%;
    max-width: none;
    margin: 1rem;
  }
  .main-panel-detail {
    width: 100%;
    max-width: none;
    margin: 0 1rem 1rem;
    overflow-y: visible;
  }
}

/* ===== Modal (clientes) ===== */
.modal {
  position: fixed;
  inset: 0; /* top:0; right:0; bottom:0; left:0 */
  display: flex;
  align-items: center;
  justify-content: center;
  background: rgba(0,0,0,0.45);
  z-index: 1000;
}
.modal[hidden] {
  display: none;
}

.modal__dialog {
  background: #fff;
  border-radius: 12px;
  max-width: 720px;
  width: clamp(320px, 90vw, 720px);
  max-height: 90vh;
  display: flex;
  flex-direction: column;
  box-shadow: 0 10px 30px rgba(0,0,0,0.2);
  animation: modalFadeIn 0.25s ease;
}

.modal__header,
.modal__footer {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 14px 18px;
  background: #f9f9f9;
  border-bottom: 1px solid #e2e2e2;
}
.modal__footer {
  border-top: 1px solid #e2e2e2;
  border-bottom: none;
}

.modal__title {
  font-size: 1.1rem;
  font-weight: 600;
}

.modal__close {
  background: transparent;
  border: none;
  font-size: 1.25rem;
  line-height: 1;
  cursor: pointer;
  color: #555;
}
.modal__close:hover {
  color: #000;
}

.modal__body {
  padding: 18px;
  overflow-y: auto;
  flex: 1;
}

.modal__footer button {
  min-width: 90px;
}

/* Simple grid for form fields */
.grid-2 {
  display: grid;
  grid-template-columns: 1fr 1fr;
  gap: 12px;
}
@media (max-width: 700px) {
  .grid-2 {
    grid-template-columns: 1fr;
  }
}

/* Row actions (Ver/Editar/Borrar en línea) */
.row-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: nowrap;
}

/* Animación de entrada */
@keyframes modalFadeIn {
  from { opacity: 0; transform: translateY(20px); }
  to   { opacity: 1; transform: translateY(0); }
}


/* ===== Responsive tables (Clientes) ===== */

/* The wrapper enables horizontal scroll on narrow screens */
.table-wrapper {
  width: 100%;
  overflow-x: auto;              /* allow horizontal scroll */
  -webkit-overflow-scrolling: touch; /* smooth scrolling on iOS */
}

/* Keep table layout stable; on mobile we’ll force a min-width */
.table-ui {
  width: 100%;
  border-collapse: collapse;
  border-spacing: 0;
  table-layout: auto;            /* or fixed; see note below */
}

/* Cells behave nicely in a scrollable table */
.table-ui th,
.table-ui td {
  padding: 0.6rem 0.75rem;
  vertical-align: middle;
  white-space: normal;           /* default on desktop */
}

/* Actions row stays on a single line */
.row-actions {
  display: flex;
  gap: 0.4rem;
  flex-wrap: nowrap;
}

/* Mobile: force the table to be wider than the viewport so it scrolls,
   and prevent content from stacking on top of each other. */
@media (max-width: 768px) {
  .table-ui {
    min-width: 720px;            /* adjust as needed (>= total column widths) */
  }
  .table-ui th,
  .table-ui td {
    white-space: nowrap;         /* keep each cell on one line for horizontal scroll */
  }
}


/* ===== Split Detail Layout ===== */
.detail-container {
  display: flex;
  height: calc(100vh - 60px); /* minus header */
}

.side-panel {
  flex: 0 0 20%;
  min-width: 180px;
  max-width: 240px;
  border-right: 1px solid #e2e2e2;
  padding: 1rem;
  background: #fafafa;
}

.side-panel h3 {
  margin-top: 0;
  font-size: 1rem;
  font-weight: 600;
}

.side-panel ul {
  list-style: none;
  padding: 0;
  margin: 1rem 0;
}
.side-panel li {
  padding: 0.5rem 0;
  cursor: pointer;
  color: #0070d2;
}
.side-panel li:hover {
  text-decoration: underline;
}

.side-panel .nav-back {
  display: block;
  margin-top: 2rem;
  font-size: 0.9rem;
  color: #444;
}

/* Main detail panel */
.main-panel-detail {
  flex: 1;
  padding: 1rem 1.25rem;
  overflow-y: auto;
}

/* Tabs */
.tabs {
  display: flex;
  gap: 0.5rem;
  border-bottom: 1px solid #ddd;
  margin-bottom: 1rem;
}
.tab {
  padding: 0.5rem 1rem;
  border: none;
  background: none;
  cursor: pointer;
  font-weight: 500;
}
.tab.active {
  border-bottom: 3px solid #0070d2;
  color: #0070d2;
  font-weight: 600;
}
.tab-content {
  display: none;
}
.tab-content.active {
  display: block;
}

/* Responsive: stack panels on mobile */
@media (max-width: 768px) {
  .detail-container {
    flex-direction: column;
  }
  .side-panel {
    flex: none;
    width: 100%;
    max-width: 100%;
    border-right: none;
    border-bottom: 1px solid #e2e2e2;
  }
}

.client-summary {
  background: #fff;
  border: 1px solid #eee;
  border-radius: 8px;
  padding: .75rem .9rem;
  margin-bottom: .75rem;
}

.kv > div {
  padding: .25rem 0;
  border-bottom: 1px dashed #eee;
}
.kv > div:last-child { border-bottom: none; }

.client-summary--stacked {
  background: #fff;
  border: 1px solid #eee;
  border-radius: 10px;
  padding: .75rem .9rem;
  margin-top: .5rem;
}

.client-field { margin-bottom: .75rem; }
.client-field:last-child { margin-bottom: 0; }

.client-label {
  font-size: 0.75rem;
  font-weight: 600;
  color: #666;
  margin-bottom: 0.15rem;
  text-transform: uppercase;
  letter-spacing: 0.03em;
}

.client-value {
  font-size: 0.95rem;
  color: #111;
  word-break: break-word;
}

.client-value.multiline {
  white-space: pre-wrap;  /* preserves line breaks */
}


/* Right drawer variant */
.drawer--right { right: -420px; left: auto; width: 420px; position: fixed; top:0; bottom:0; background:#fff; box-shadow: -8px 0 24px rgba(0,0,0,.08); transition: right .2s ease; z-index: 1100; }
.drawer--right.open { right: 0; }
.drawer--right .drawer__content{ padding: 1rem; overflow-y:auto; height: calc(100vh - 60px); }

/* Job lines grid: Categoría | Precio | Remove */
.job-lines .line {
  display: grid;
  grid-template-columns: minmax(160px, 1fr) 120px 36px;
  gap: .5rem;
  align-items: center;
  margin-bottom: .5rem;
}
.job-lines .line select,
.job-lines .line input[type="number"] { width: 100%; }
.job-lines .line button { width: 36px; }


/* ===== Right job drawer (independent from global .drawer) ===== */
.job-drawer {
  position: fixed;
  top: 0;
  bottom: 0;
  right: -420px;           /* hidden off-screen by default */
  width: 420px;
  background: #fff;
  box-shadow: -8px 0 24px rgba(0,0,0,.08);
  z-index: 1100;
  transition: right .2s ease;
  display: flex;
  flex-direction: column;
}
.job-drawer.open {
  right: 0;                /* slide in */
}
.job-drawer .drawer__head {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 12px 16px;
  border-bottom: 1px solid #eee;
}
.job-drawer .drawer__title { font-size: 1rem; font-weight: 600; margin: 0; }
.job-drawer .drawer__close { background: transparent; border: 0; font-size: 1.1rem; cursor: pointer; }
.job-drawer .drawer__content {
  padding: 1rem;
  overflow-y: auto;
  flex: 1;
}


/* Side panel fields */
.client-summary.client-summary--stacked {
  display: flex;
  flex-direction: column;
  gap: .75rem;
}

/* On small screens, show fields in 2 columns */
@media (max-width: 768px) {
  .client-summary.client-summary--stacked {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: .5rem .75rem; /* row-gap / column-gap */
  }

  .client-summary.client-summary--stacked .client-field {
    margin: 0;
  }

  /* Labels smaller, values take more weight */
  .client-summary.client-summary--stacked .client-label {
    font-size: .75rem;
    color: #666;
    margin-bottom: .25rem;
    display: block;
  }
  .client-summary.client-summary--stacked .client-value {
    font-size: .9rem;
    font-weight: 500;
  }

  /* Make Ubicación span across both columns */
  .client-summary.client-summary--stacked .client-field:last-child {
    grid-column: 1 / -1;
  }
}

/* ===== Job Edit Drawer base (desktop) ===== */
.job-drawer {
  position: fixed;
  top: 0;
  right: 0;
  width: 420px;              /* desktop width */
  max-width: 100vw;
  height: 100dvh;
  transform: translateX(100%);
  transition: transform .25s ease;
  background: #fff;
  box-shadow: -6px 0 16px rgba(0,0,0,.12);
  z-index: 1050;
  display: flex;
  flex-direction: column;
}

.job-drawer.open { transform: translateX(0); }

.job-drawer .drawer__head {
  padding: .9rem 1rem;
  border-bottom: 1px solid #eee;
  display: flex;
  align-items: center;
  justify-content: space-between;
  /* Safe areas for iPhone notch */
  padding-left: max(1rem, env(safe-area-inset-left));
  padding-right: max(1rem, env(safe-area-inset-right));
}

.job-drawer .drawer__content {
  padding: 1rem;
  overflow: auto;
  -webkit-overflow-scrolling: touch;
}

/* Form elements inside drawer */
#jobEditForm label { display:block; }
#jobEditForm select,
#jobEditForm input[type="text"],
#jobEditForm input[type="tel"],
#jobEditForm input[type="email"],
#jobEditForm input[type="number"],
#jobEditForm input[type="datetime-local"],
#jobEditForm textarea {
  width: 100%;
  max-width: 100%;
  font-size: 16px;           /* prevent iOS zoom on focus */
  box-sizing: border-box;
}

/* Lines editor: stack on small screens */
.job-lines .line {
  display: grid;
  grid-template-columns: 1fr 120px auto; /* category | price | remove */
  gap: .5rem;
  align-items: center;
  margin-bottom: .5rem;
}
@media (max-width: 480px) {
  .job-lines .line {
    grid-template-columns: 1fr 1fr auto; /* more balanced on very small */
  }
}

/* Make primary button full width on mobile */
#jobEditSave { width: 100%; }

/* ===== Mobile sheet behavior ===== */
@media (max-width: 768px) {
  .job-drawer {
    width: 100vw;                /* take full width */
    max-width: 100vw;
    height: 100dvh;              /* viewport height with iOS dyn. bars */
    border-radius: 0;            /* no rounded corners on sheet */
  }
  .job-drawer .drawer__content {
    padding-left: max(1rem, env(safe-area-inset-left));
    padding-right: max(1rem, env(safe-area-inset-right));
    padding-bottom: calc(1rem + env(safe-area-inset-bottom));
  }
}

/* Ensure no horizontal scroll leaks on body when drawer is open */
body.drawer-open {
  overflow: hidden;
  touch-action: none;
}

/* Optional: make table cells wrap nicely to avoid expanding the viewport */
.table-ui td, .table-ui th {
  word-break: break-word;
}

.client-value a.client-link { text-decoration: underline; color: inherit; }
.client-link.is-disabled { opacity:.6; pointer-events:none; text-decoration: none; }

.action-btn {
  display: inline-flex;
  align-items: center;
  gap: 0.35rem;
  background: #f9f9f9;
  padding: 0.45rem 0.75rem;
  border-radius: 6px;
  font-size: 0.9rem;
  font-weight: 500;
  text-decoration: none;
  color: inherit;
  transition: background 0.2s;
}
.action-btn:hover {
  background: #ececec;
}
.action-btn svg {
  flex-shrink: 0;
}

.icon-btn {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  width: 70px;
  height: 2.25rem;
  background: #f9f9f9;
  border-radius: 6px;
  transition: background 0.2s;
  cursor: pointer;
  border: none;
}
.icon-btn:hover {
  background: #ececec;
}
.icon-btn svg {
  pointer-events: none;
}

#jobEditRecurringChk:disabled,
#jobEditRecurringMonths:disabled {
  opacity: 0.6;
  cursor: not-allowed;
}

/* === Sidebar Totals === */
#sidebarTotals {
  margin-top: 1.5rem;
  padding-top: 1rem;
  border-top: 1px solid #e4e7eb;
  display: flex;
  flex-direction: column;  /* default desktop layout */
  gap: 1rem;
}

/* On small/mobile screens: show totals side by side */
@media (max-width: 768px) {
  #sidebarTotals {
    flex-direction: row;
    justify-content: space-between;
    gap: 2rem;
  }
  .sidebar-total {
    flex: 1;
    text-align: center;
  }
}
.sidebar-total {
  display: flex;
  flex-direction: column;
}
.sidebar-total .label {
  font-size: 0.8rem;
  color: #666;
  font-weight: 500;
  margin-bottom: 0.25rem;
}
.sidebar-total .value {
  font-size: 1.4rem;
  font-weight: 700;
  color: #111;
}

/* === Login Logo === */
.login-logo img {
  max-height: 30px !important;   /* control logo height */
  width: auto;        /* keep aspect ratio */
  display: inline-block;
}

.login-logo {
  text-align: center;
  margin-bottom: 1rem;
}

/* === Login Form === */
#loginForm {
  display: flex;
  flex-direction: column;
  gap: 0.75rem;   /* space between inputs and button */
}

#loginForm input,
#loginForm button {
  padding: 0.6rem 0.8rem;
  font-size: 1rem;
  border: 1px solid #ccc;
  border-radius: 6px;
}

#loginForm button {
  background: #135f56;   /* your brand color */
  color: #fff;
  font-weight: 600;
  cursor: pointer;
  border: none;
}

#loginForm button:hover {
  background: #0f4c45;
}

/* ===== Cashflow Table (fill card, compact columns) ===== */
.cashflow-page .table-wrapper {
  margin-top: 0.5rem;
  overflow-x: auto;
}

.cashflow-page .table-ui {
  width: 100%;                 /* table fills the card */
  border-collapse: collapse;
  font-size: 0.9rem;
  table-layout: fixed;          /* distribute columns based on width */
}

.cashflow-page .table-ui th,
.cashflow-page .table-ui td {
  padding: 0.35rem 0.5rem;
  border-bottom: 1px solid #e6e8ec;
  line-height: 1.3;
}

.cashflow-page .table-ui th {
  background: #f6f7f9;
  font-weight: 600;
  text-align: left;
}

.cashflow-page .table-ui th:first-child,
.cashflow-page .table-ui td:first-child {
  width: 70%;                   /* concept column takes most */
  text-align: left;
}

.cashflow-page .table-ui th:last-child,
.cashflow-page .table-ui td:last-child {
  width: 30%;                   /* amount column shrinks */
  text-align: right;
  font-variant-numeric: tabular-nums;
  white-space: nowrap;
}

.cashflow-page .table-ui tbody tr:nth-child(odd) {
  background: #fafafa;
}

.cashflow-page .table-ui tbody tr:hover {
  background: #f1f7ff;
}

/* ===== Cashflow: KPI strip ===== */
.cashflow-page .kpi-strip {
  display: flex;
  flex-wrap: wrap;
  gap: 1rem;
  margin: 0.75rem 0 1.25rem;
}

.cashflow-page .kpi {
  flex: 1 1 200px;                  /* each box grows/shrinks */
  background: #fff;
  border: 1px solid #d8dde6;
  border-radius: 8px;
  padding: 0.75rem 1rem;
  box-shadow: 0 1px 3px rgba(0,0,0,0.05);
}

.cashflow-page .kpi .label {
  font-size: 0.85rem;
  color: #555;
  margin-bottom: 0.35rem;
}

.cashflow-page .kpi .value {
  font-weight: 700;
  font-size: 1.25rem;
  color: #111;
}

.cashflow-page .kpi .value.result-positive {
  color: #0a7a2f;   /* green for positive results */
}

.cashflow-page .kpi .value.result-negative {
  color: #b00020;   /* red for negative results */
}

/* Mobile: stack KPIs full width */
@media (max-width: 700px) {
  .cashflow-page .kpi {
    flex: 1 1 100%;
  }
}

/* ==== Dashboard (home) ==== */
.dashboard-page .kpi-strip {
  display: flex; gap: .75rem; flex-wrap: wrap; margin: .25rem 0 1rem;
}
.dashboard-page .kpi {
  flex: 1 1 160px; background:#fff; border:1px solid #d8dde6; border-radius:8px; padding:.6rem .8rem;
}
.dashboard-page .kpi .label { font-size:.85rem; color:#555; margin-bottom:.2rem; }
.dashboard-page .kpi .value { font-weight:700; font-size:1.15rem; }

.dashboard-page .card {
  background:#fff; border:1px solid #d8dde6; border-radius:8px; padding:1rem;
  box-shadow: 0 2px 4px rgba(0,0,0,.04);
}
.dashboard-page .flex-between { display:flex; align-items:center; justify-content:space-between; gap:.5rem; }

.dashboard-page .table-wrapper.compact .table-ui th,
.dashboard-page .table-wrapper.compact .table-ui td {
  padding: .4rem .5rem;
  white-space: nowrap;
}

/* Week grid */
.week-grid {
  display:grid; grid-template-columns: repeat(7, 1fr); gap:.5rem; margin-top:.5rem;
}
@media (max-width: 900px){
  .week-grid { grid-template-columns: 1fr 1fr; }
}
@media (max-width: 560px){
  .week-grid { grid-template-columns: 1fr; }
}
.week-col { border:1px solid #e6e8ec; border-radius:8px; overflow:hidden; background:#fff; }
.week-col-head { font-weight:600; padding:.5rem .6rem; background:#f6f7f9; border-bottom:1px solid #e6e8ec; }
.week-col-body { padding:.5rem; display:flex; flex-direction:column; gap:.4rem; }
.slot {
  display:block; text-decoration:none; border:1px solid #e6e8ec; border-radius:8px; padding:.45rem .55rem;
  background:#fff;
}
.slot:hover { background:#f5fafc; }
.slot-time { font-size:.8rem; color:#444; }
.slot-title { font-weight:600; }
.slot-sub { font-size:.8rem; color:#666; }
.slot--empty { color:#888; font-style:italic; border:1px dashed #e0e0e0; background:#fafafa; }
.week-label { font-weight:600; }

/* Filters inline */
.dashboard-page .filters {
  display:flex;
  gap:.5rem;
  align-items:flex-end;
}
.dashboard-page .filters label {
  font-size:.85rem;
  display:flex;
  flex-direction:column;
}
.dashboard-page .filters select {
  padding:.3rem .4rem;
}

/* Modal */
.modal {
  position:fixed; inset:0;
  background:rgba(0,0,0,.5);
  display:flex; align-items:center; justify-content:center;
  z-index:2000;
}
.modal-content {
  background:#fff;
  padding:1rem;
  border-radius:8px;
  width:100%; max-width:400px;
}
.modal-content h3 { margin-top:0; }
.modal-actions { display:flex; gap:.5rem; justify-content:flex-end; margin-top:.75rem; }


/* Make iframe fill its wrapper */
.iframe-wrapper {
  width: 100%;
  height: calc(100vh - 200px); /* adjust depending on header/footer size */
  min-height: 400px;
  display: flex;
}

.iframe-wrapper iframe {
  flex: 1;
  width: 100%;
  height: 100%;
  border: none !important;
  outline: none !important;
  box-shadow: none !important;
  background: transparent;
}
}

/* Date pickers */

/* ===== Common date picker styles ===== */
.side-panel .date-filter {
  display: grid;
  grid-template-columns: 1fr;      /* stack on narrow sidepanel */
  gap: 0.5rem;
  margin-top: 0.5rem;
}

@media (min-width: 720px) {
  /* if your sidepanel is wide enough, show two columns */
  .side-panel .date-filter.two-cols {
    grid-template-columns: 1fr 1fr; /* Desde | Hasta side by side */
    align-items: end;
  }
}

.side-panel .date-field {
  display: flex;
  flex-direction: column;
  gap: 0.25rem;
}

.side-panel .date-field label {
  font-size: 0.88rem;
  color: #444;
}

.side-panel input[type="date"],
.side-panel input[type="datetime-local"],
.side-panel input[type="time"] {
  width: 100%;
  -webkit-appearance: none;
  appearance: none;
  font: inherit;
  line-height: 1.2;
  padding: 0.45rem 0.6rem;
  border: 1px solid #d8dde6;
  border-radius: 6px;
  background: #fff;
  color: #111;
  box-sizing: border-box;          /* critical to avoid overflow */
}

.side-panel input[type="date"]:focus,
.side-panel input[type="datetime-local"]:focus,
.side-panel input[type="time"]:focus {
  outline: none;
  border-color: #6aa5ff;
  box-shadow: 0 0 0 3px rgba(106,165,255,0.2);
}

/* Compact row with the apply button aligned right */
.side-panel .date-actions {
  display: flex;
  gap: 0.5rem;
  justify-content: flex-end;
}

/* Make buttons and selects in sidepanel align visually */
.side-panel select,
.side-panel button {
  width: 100%;
  box-sizing: border-box;
}
@media (min-width: 720px) {
  .side-panel .date-actions button { width: auto; }
}


.datepicker-input {
  width: 100%;
  padding: 0.4rem 0.6rem;
  border: 1px solid #d1d5db;
  border-radius: 6px;
  font-size: 0.9rem;
}


/* collapse sidepanel in mobile */

/* ===== Mobile collapsible side-panel ===== */
.sidepanel-header {
  display: flex;
  align-items: center;
  justify-content: space-between;
  gap: .5rem;
  margin-bottom: .5rem;
}

.sp-toggle {
  display: none;                 /* hidden on desktop */
  border: 1px solid #d8dde6;
  background: #009688;
  border-radius: 6px;
  padding: .35rem .6rem;
  font-size: .85rem;
  line-height: 1;
  cursor: pointer;
}
.sp-toggle:hover { background: #00796b; }

.sidepanel-content {
  max-height: none;
  overflow: visible;
  transition: max-height .25s ease;
}

/* Mobile behavior */
@media (max-width: 900px) {
  .sp-toggle { display: inline-block; }      /* show toggle only on mobile */
  .sidepanel-content {
    max-height: 1200px;                      /* enough for typical filters */
    overflow: hidden;
  }
  .side-panel.collapsed .sidepanel-content {
    max-height: 0;                           /* collapsed */
  }
}

@media (max-width: 900px) {
  .sidepanel-content.is-collapsed {
    max-height: 0;
    overflow: hidden;
  }
}

/* Sidebar form labels */
.side-panel label {
  font-size: 0.9rem;   /* adjust as you like */
  font-weight: 500;    /* optional, makes it stand out */
  display: block;      /* keeps input below the label */
  margin-top: 0.5rem;  /* space above each label */
}
