/* ================================================================
   quoERP — Design System CSS
   Stack: PHP/MySQL · cPanel MVP
   MENRICORP © 2026
   ================================================================ */

/* ── Variables ──────────────────────────────────────────── */
:root {
  --bg0: #f4f5f7;
  --bg1: #ffffff;
  --bg2: #f0f2f5;
  --bg3: #e8eaed;
  --txt1: #0d1117;
  --txt2: #4a5568;
  --txt3: #8896a5;
  --brd: #e2e6ea;
  --brd2: #c9d0d9;
  --acc: #1B3A6B;
  --acc2: #2E5FAA;
  --acc3: #EBF2FA;
  --ora: #E8501A;
  --orl: #FFF3EE;
  --grn: #1a7a4a;
  --gnl: #edfaf3;
  --red: #c0392b;
  --rdl: #fdeaea;
  --pur: #6B3FA0;
  --prl: #f5eeff;
  --yel: #8B6914;
  --yll: #FFF8E1;
  --shadow: 0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
  --shadow2: 0 4px 16px rgba(0,0,0,.10);
  --rad: 8px;
  --rad2: 12px;
  --rad3: 16px;
  --font: 'DM Sans', system-ui, -apple-system, sans-serif;
  --mono: 'DM Mono', 'Courier New', monospace;
  --sidebar: 240px;
  --topbar: 56px;
  --transition: .18s ease;
}

[data-theme="dark"] {
  --bg0: #0d1117;
  --bg1: #161b22;
  --bg2: #1c2128;
  --bg3: #262c36;
  --txt1: #e6edf3;
  --txt2: #8d96a0;
  --txt3: #4a5568;
  --brd: #30363d;
  --brd2: #444c56;
  --acc: #4d8dd4;
  --acc2: #6ba3e0;
  --acc3: #1a2840;
  --ora: #f07040;
  --orl: #2a1508;
  --grn: #3fb87a;
  --gnl: #0d2a1a;
  --red: #e05555;
  --rdl: #2a0d0d;
  --pur: #a070d8;
  --prl: #1e1030;
  --yel: #d4a030;
  --yll: #1e1800;
  --shadow: 0 1px 3px rgba(0,0,0,.3), 0 1px 2px rgba(0,0,0,.2);
  --shadow2: 0 4px 16px rgba(0,0,0,.4);
}

/* ── Reset ──────────────────────────────────────────────── */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
html, body { height: 100%; }
body {
  font-family: var(--font);
  font-size: 14px;
  line-height: 1.6;
  background: var(--bg0);
  color: var(--txt1);
  transition: background var(--transition), color var(--transition);
  -webkit-font-smoothing: antialiased;
}
a { color: var(--acc); text-decoration: none; }
a:hover { text-decoration: underline; }
img { max-width: 100%; }
input, button, select, textarea { font-family: var(--font); }

/* ── AUTH LAYOUT ────────────────────────────────────────── */
.auth-body { background: var(--bg0); display: flex; align-items: center; justify-content: center; min-height: 100vh; }
.auth-wrap  { width: min(440px, 96vw); display: flex; flex-direction: column; gap: 16px; position: relative; }
.auth-brand { display: flex; align-items: center; gap: 12px; padding: 0 4px; }
.auth-logo-mark { width: 42px; height: 42px; background: var(--acc); color: #fff; border-radius: 12px; display: flex; align-items: center; justify-content: center; font-size: 20px; font-weight: 700; font-family: var(--mono); flex-shrink: 0; }
.auth-logo-text { font-size: 22px; font-weight: 700; color: var(--acc); letter-spacing: -.5px; line-height: 1; }
.auth-logo-text span { font-weight: 300; color: var(--txt3); }
.auth-logo-sub { font-size: 12px; color: var(--txt3); margin-top: 2px; }
.auth-card { background: var(--bg1); border: 1px solid var(--brd); border-radius: var(--rad3); padding: 36px; box-shadow: var(--shadow2); }
.auth-title { font-size: 20px; font-weight: 600; color: var(--txt1); margin-bottom: 4px; }
.auth-subtitle { font-size: 13px; color: var(--txt3); margin-bottom: 24px; }
.auth-footer { font-size: 11px; color: var(--txt3); text-align: center; padding: 0 4px; }
.auth-footer a { color: var(--txt3); }
.auth-footer a:hover { color: var(--acc); }
.auth-theme-btn { position: absolute; top: 0; right: 0; background: none; border: 1px solid var(--brd); border-radius: var(--rad); padding: 6px 8px; cursor: pointer; color: var(--txt3); font-size: 15px; transition: color var(--transition), border-color var(--transition); }
.auth-theme-btn:hover { color: var(--txt1); border-color: var(--brd2); }

/* ── APP LAYOUT ─────────────────────────────────────────── */
.topbar {
  position: fixed; top: 0; left: 0; right: 0; z-index: 100;
  height: var(--topbar);
  background: var(--bg1);
  border-bottom: 1px solid var(--brd);
  display: flex; align-items: center; padding: 0 14px; gap: 10px;
  box-shadow: var(--shadow);
}
.erp-body { display: flex; padding-top: var(--topbar); height: 100vh; overflow: hidden; }
.main { flex: 1; min-height: 0; overflow: hidden; background: var(--bg0); display: flex; flex-direction: column; }
.page-content { flex: 1; padding: 20px 24px 40px; min-width: 0; display: flex; flex-direction: column; gap: 0; overflow-y: auto; }

/* ── TAB BAR ─────────────────────────────────────────────── */
.tab-bar {
  display: flex;
  align-items: center;
  flex-shrink: 0;
  height: 36px;
  background: var(--bg1);
  border-bottom: 1px solid var(--brd);
  padding: 0 6px;
  overflow-x: auto;
  overflow-y: hidden;
  scrollbar-width: none;
  gap: 2px;
  user-select: none;
}
.tab-bar::-webkit-scrollbar { display: none; }

.tab-item {
  display: flex;
  align-items: center;
  gap: 5px;
  flex-shrink: 0;
  padding: 0 10px 0 9px;
  height: 28px;
  border-radius: 6px;
  cursor: pointer;
  white-space: nowrap;
  max-width: 200px;
  min-width: 80px;
  background: transparent;
  color: var(--txt3);
  font-size: 11.5px;
  font-weight: 500;
  transition: background .12s, color .12s;
  position: relative;
  border: 1px solid transparent;
}
.tab-item:hover {
  background: var(--bg2);
  color: var(--txt1);
}
.tab-item.active {
  background: var(--acc3, #EFF6FF);
  color: var(--acc);
  font-weight: 600;
  border-color: var(--brd);
}
.tab-item .tab-ico {
  font-size: 12px;
  flex-shrink: 0;
}
.tab-item .tab-lbl {
  overflow: hidden;
  text-overflow: ellipsis;
  flex: 1;
  min-width: 0;
}
.tab-item .tab-x {
  flex-shrink: 0;
  width: 16px;
  height: 16px;
  border-radius: 3px;
  border: none;
  background: transparent;
  color: var(--txt3);
  font-size: 14px;
  line-height: 1;
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  opacity: 0;
  transition: opacity .1s, background .1s;
  padding: 0;
}
.tab-item:hover .tab-x,
.tab-item.active .tab-x { opacity: 1; }
.tab-item .tab-x:hover { background: var(--red-bg, #fee2e2); color: var(--red); }

.tab-add-btn {
  flex-shrink: 0;
  width: 26px;
  height: 26px;
  border: 1px dashed var(--brd2);
  border-radius: 6px;
  background: transparent;
  color: var(--txt3);
  cursor: pointer;
  display: flex;
  align-items: center;
  justify-content: center;
  font-size: 14px;
  transition: background .12s, color .12s, border-color .12s;
  margin-left: 2px;
}
.tab-add-btn:hover { background: var(--bg2); color: var(--acc); border-color: var(--acc); }

/* ── TAB FRAMES (iframes container) ────────────────────── */
.tab-frames {
  flex: 1;
  min-height: 0;
  position: relative;
  overflow: hidden;
  background: var(--bg2);
}
.tab-frame {
  position: absolute;
  top: 0; left: 0;
  width: 100%; height: 100%;
  border: none;
  display: none;
  background: var(--bg2);
}
.tab-frame.active {
  display: block;
}

/* ── Frame-body (contenido dentro del iframe) ──────────── */
body.frame-body { background: var(--bg2, #f5f6fa); }
body.frame-body .page-content { min-height: 100vh; }

/* ── TOPBAR ELEMENTS ────────────────────────────────────── */
.topbar-logo { display: flex; align-items: center; gap: 8px; font-weight: 700; font-size: 16px; color: var(--acc); letter-spacing: -.3px; min-width: calc(var(--sidebar) - 28px); text-decoration: none; flex-shrink: 0; white-space: nowrap; }
.topbar-logo:hover { text-decoration: none; }
.topbar-logo .q { background: var(--acc); color: #fff; width: 28px; height: 28px; border-radius: 8px; display: flex; align-items: center; justify-content: center; font-size: 14px; font-weight: 700; font-family: var(--mono); }
.logo-erp { font-weight: 300; color: var(--txt3); }

.company-switcher { display: flex; align-items: center; gap: 8px; padding: 5px 10px; border: 1px solid var(--brd); border-radius: var(--rad); cursor: pointer; background: var(--bg2); font-size: 12px; color: var(--txt1); min-width: 200px; max-width: 260px; transition: border-color var(--transition); }
.company-switcher:hover { border-color: var(--brd2); }
.co-dot { width: 24px; height: 24px; border-radius: 6px; display: flex; align-items: center; justify-content: center; font-size: 10px; font-weight: 700; color: #fff; flex-shrink: 0; }
.co-info { flex: 1; min-width: 0; }
.co-name { font-weight: 500; font-size: 12px; white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.co-branch { font-size: 10px; color: var(--txt3); white-space: nowrap; overflow: hidden; text-overflow: ellipsis; }
.co-branch .ti { font-size: 10px; }

.topbar-search { flex: 1; max-width: 340px; position: relative; }
.topbar-search input { width: 100%; padding: 7px 10px 7px 32px; border: 1px solid var(--brd); border-radius: var(--rad); background: var(--bg2); color: var(--txt1); font-size: 13px; outline: none; transition: border-color var(--transition), background var(--transition); }
.topbar-search input:focus { border-color: var(--acc); background: var(--bg1); }
.topbar-search > .ti { position: absolute; left: 10px; top: 50%; transform: translateY(-50%); color: var(--txt3); font-size: 15px; pointer-events: none; }

.topbar-right { margin-left: auto; display: flex; align-items: center; gap: 4px; }
.tb-btn { width: 34px; height: 34px; border-radius: var(--rad); border: none; background: transparent; cursor: pointer; display: flex; align-items: center; justify-content: center; color: var(--txt2); font-size: 18px; transition: background var(--transition), color var(--transition); position: relative; text-decoration: none; }
.tb-btn:hover { background: var(--bg2); color: var(--txt1); }
.badge { position: absolute; top: 5px; right: 5px; width: 8px; height: 8px; background: var(--ora); border-radius: 50%; border: 2px solid var(--bg1); }

.avatar-btn { background: none; border: none; cursor: pointer; padding: 2px; border-radius: 50%; }
.av { border-radius: 50%; display: flex; align-items: center; justify-content: center; font-weight: 600; color: #fff; flex-shrink: 0; position: relative; overflow: hidden; font-family: var(--mono); }
.av img { width: 100%; height: 100%; object-fit: cover; position: absolute; inset: 0; }
.av-top { width: 32px; height: 32px; font-size: 11px; border: 2px solid var(--brd); transition: border-color var(--transition); }
.avatar-btn:hover .av-top { border-color: var(--acc); }
.online-dot { position: absolute; bottom: 0; right: 0; width: 9px; height: 9px; border-radius: 50%; border: 2px solid var(--bg1); }
.online { background: #22c55e; }
.away   { background: #f59e0b; }
.busy   { background: #ef4444; }
.offline{ background: var(--txt3); }

/* ── SIDEBAR ────────────────────────────────────────────── */
.sidebar { width: var(--sidebar); background: var(--bg1); border-right: 1px solid var(--brd); display: flex; flex-direction: column; overflow: hidden; flex-shrink: 0; transition: width var(--transition); position: sticky; top: var(--topbar); height: calc(100vh - var(--topbar)); }
.sidebar.collapsed { width: 52px; }
.sidebar-scroll { flex: 1; overflow-y: scroll; padding: 8px; scrollbar-gutter: stable; }
.sidebar-scroll::-webkit-scrollbar { width: 5px; }
.sidebar-scroll::-webkit-scrollbar-track { background: transparent; }
.sidebar-scroll::-webkit-scrollbar-thumb { background: var(--brd2); border-radius: 3px; }
.sidebar-scroll::-webkit-scrollbar-thumb:hover { background: var(--txt3); }
.nav-section { margin-bottom: 4px; }
.nav-label { font-size: 10px; font-weight: 600; color: var(--txt3); letter-spacing: .6px; text-transform: uppercase; padding: 8px 8px 4px; white-space: nowrap; overflow: hidden; }
.nav-item { display: flex; align-items: center; gap: 9px; padding: 7px 10px; border-radius: var(--rad); cursor: pointer; transition: background var(--transition), color var(--transition); color: var(--txt2); font-size: 13px; font-weight: 400; white-space: nowrap; overflow: hidden; position: relative; border: none; background: transparent; width: 100%; text-align: left; text-decoration: none; }
.nav-item:hover { background: var(--bg2); color: var(--txt1); }
.nav-item.active, .nav-item[aria-current="page"] { background: var(--acc3); color: var(--acc); font-weight: 500; }
.nav-item .ti { font-size: 17px; flex-shrink: 0; }
.nav-text { flex: 1; overflow: hidden; text-overflow: ellipsis; }
.nav-badge { font-size: 10px; font-weight: 700; padding: 1px 6px; border-radius: 10px; background: var(--ora); color: #fff; flex-shrink: 0; }
.nav-arrow { font-size: 13px; color: var(--txt3); margin-left: auto; transition: transform var(--transition); flex-shrink: 0; }
.nav-item.open .nav-arrow, .nav-item[aria-expanded="true"] .nav-arrow { transform: rotate(90deg); }
.subnav { overflow: hidden; max-height: 0; transition: max-height .28s ease; }
.subnav.open { max-height: 1400px; }
.subnav .nav-item { padding-left: 34px; font-size: 12.5px; }
.sidebar-footer { padding: 8px; border-top: 1px solid var(--brd); }
.sidebar.collapsed .nav-label, .sidebar.collapsed .nav-text, .sidebar.collapsed .nav-badge, .sidebar.collapsed .nav-arrow, .sidebar.collapsed .co-info, .sidebar.collapsed .btn-text { display: none; }
.sidebar.collapsed .nav-item { justify-content: center; padding: 8px; }

/* ── PAGE CHROME ────────────────────────────────────────── */
.breadcrumb { display: flex; align-items: center; gap: 6px; padding: 12px 24px 0; font-size: 12px; color: var(--txt3); }
.breadcrumb span { color: var(--txt2); }
.breadcrumb .ti { font-size: 11px; }
.page-header { display: flex; align-items: flex-start; gap: 12px; padding: 16px 0 14px; }
.page-title { font-size: 20px; font-weight: 600; color: var(--txt1); letter-spacing: -.3px; line-height: 1.3; }
.page-sub, .page-subtitle { font-size: 13px; color: var(--txt3); margin-top: 2px; }
.ph-actions { margin-left: auto; display: flex; gap: 8px; align-items: center; flex-shrink: 0; }
.content { flex: 1; padding: 20px 24px 40px; min-width: 0; }
/* .page-content wraps all view output in the layout and provides consistent padding */

/* ── BUTTONS ────────────────────────────────────────────── */
.btn { display: inline-flex; align-items: center; gap: 6px; padding: 7px 14px; border-radius: var(--rad); font-size: 13px; font-weight: 500; cursor: pointer; border: 1px solid var(--brd); background: var(--bg1); color: var(--txt1); font-family: var(--font); transition: background var(--transition), border-color var(--transition), color var(--transition); white-space: nowrap; text-decoration: none; }
.btn:hover { background: var(--bg2); border-color: var(--brd2); text-decoration: none; }
.btn:active { transform: scale(.98); }
.btn.primary { background: var(--acc); color: #fff; border-color: var(--acc); }
.btn.primary:hover { background: var(--acc2); border-color: var(--acc2); }
.btn.danger { background: var(--red); color: #fff; border-color: var(--red); }
.btn.ghost { border-color: transparent; background: transparent; }
.btn.ghost:hover { background: var(--bg2); }
.btn.sm { padding: 5px 10px; font-size: 12px; }
.btn.lg { padding: 10px 20px; font-size: 14px; }
.btn:disabled { opacity: .5; cursor: not-allowed; }
.btn-submit { width: 100%; padding: 11px; background: var(--acc); color: #fff; border: none; border-radius: var(--rad); font-size: 14px; font-weight: 600; font-family: var(--font); cursor: pointer; transition: background var(--transition); display: flex; align-items: center; justify-content: center; gap: 8px; margin-top: 8px; }
.btn-submit:hover { background: var(--acc2); }
.btn-submit:disabled { background: var(--brd2); cursor: not-allowed; }
.btn-spinner { width: 16px; height: 16px; border: 2px solid rgba(255,255,255,.3); border-top-color: #fff; border-radius: 50%; animation: spin .6s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* ── FORMS ──────────────────────────────────────────────── */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 14px; }
.form-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(220px, 1fr)); gap: 14px; }
.form-label { font-size: 12px; font-weight: 500; color: var(--txt2); display: flex; align-items: center; justify-content: space-between; }
.form-label-link { font-weight: 400; color: var(--acc); font-size: 11px; }
.form-label-link:hover { text-decoration: underline; }
.form-label .req { color: var(--ora); }
.form-control { padding: 8px 11px; border: 1px solid var(--brd); border-radius: var(--rad); background: var(--bg1); color: var(--txt1); font-size: 13px; font-family: var(--font); outline: none; transition: border-color var(--transition), box-shadow var(--transition); width: 100%; }
.form-control:focus { border-color: var(--acc); box-shadow: 0 0 0 3px rgba(27,58,107,.12); }
.form-control[readonly], .form-control:disabled { background: var(--bg2); color: var(--txt3); cursor: not-allowed; }
.form-control.error { border-color: var(--red); }
.form-hint { font-size: 11px; color: var(--txt3); margin-top: 2px; }
.form-hint.error { color: var(--red); }
.input-wrap { position: relative; }
.input-icon { position: absolute; left: 11px; top: 50%; transform: translateY(-50%); color: var(--txt3); font-size: 16px; pointer-events: none; }
.form-control.with-icon { padding-left: 34px; }
.input-toggle-pass { position: absolute; right: 10px; top: 50%; transform: translateY(-50%); background: none; border: none; cursor: pointer; color: var(--txt3); font-size: 16px; display: flex; padding: 2px; }
.input-toggle-pass:hover { color: var(--txt2); }
select.form-control { cursor: pointer; }
textarea.form-control { resize: vertical; min-height: 80px; }

/* ── ALERTS / FLASH ─────────────────────────────────────── */
.alert { display: flex; align-items: center; gap: 10px; padding: 11px 14px; border-radius: var(--rad); font-size: 13px; margin-bottom: 16px; }
.alert .ti { font-size: 17px; flex-shrink: 0; }
.alert-error   { background: var(--rdl); color: var(--red); border: 1px solid var(--red); }
.alert-success { background: var(--gnl); color: var(--grn); border: 1px solid var(--grn); }
.alert-info    { background: var(--acc3); color: var(--acc); border: 1px solid var(--acc); }
.flash { display: flex; align-items: center; gap: 10px; padding: 12px 24px; font-size: 13px; }
.flash .ti { font-size: 16px; }
.flash-error   { background: var(--rdl); color: var(--red); border-bottom: 1px solid var(--red); }
.flash-success { background: var(--gnl); color: var(--grn); border-bottom: 1px solid var(--grn); }

/* ── CARDS ──────────────────────────────────────────────── */
.card { background: var(--bg1); border: 1px solid var(--brd); border-radius: var(--rad2); box-shadow: var(--shadow); }
.card-header { padding: 14px 18px 12px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--brd); }
.card-title { font-size: 14px; font-weight: 600; color: var(--txt1); }
.card-body { padding: 18px; }
.card-actions { margin-left: auto; display: flex; gap: 8px; }
.card + .card { margin-top: 16px; }

/* ── STAT CARDS ─────────────────────────────────────────── */
.stats-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(160px, 1fr)); gap: 12px; margin-bottom: 20px; }
.stat-card { background: var(--bg1); border: 1px solid var(--brd); border-radius: var(--rad2); padding: 16px; }
.stat-icon { width: 36px; height: 36px; border-radius: 10px; display: flex; align-items: center; justify-content: center; font-size: 18px; margin-bottom: 10px; }
.stat-label { font-size: 11px; color: var(--txt3); font-weight: 500; letter-spacing: .3px; text-transform: uppercase; }
.stat-value { font-size: 22px; font-weight: 600; color: var(--txt1); letter-spacing: -.5px; margin-top: 2px; }
.stat-delta { font-size: 11px; font-weight: 500; display: flex; align-items: center; gap: 3px; margin-top: 4px; }
.delta-up { color: var(--grn); }
.delta-dn { color: var(--red); }

/* ── TABLES ─────────────────────────────────────────────── */
.tbl-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: 13px; }
th { padding: 10px 14px; font-size: 11px; font-weight: 600; text-transform: uppercase; letter-spacing: .4px; color: var(--txt3); border-bottom: 1px solid var(--brd); text-align: left; background: var(--bg2); white-space: nowrap; }
td { padding: 11px 14px; border-bottom: 1px solid var(--brd); color: var(--txt2); vertical-align: middle; }
tr:last-child td { border-bottom: none; }
tr:hover td { background: var(--bg2); }
.td-primary { font-weight: 500; color: var(--txt1); }
.td-mono { font-family: var(--mono); font-size: 12px; }

/* ── PILLS / BADGES ─────────────────────────────────────── */
.pill { display: inline-flex; align-items: center; gap: 4px; padding: 2px 8px; border-radius: 20px; font-size: 11px; font-weight: 600; white-space: nowrap; }
.pill.green  { background: var(--gnl); color: var(--grn); }
.pill.red    { background: var(--rdl); color: var(--red); }
.pill.blue   { background: var(--acc3); color: var(--acc); }
.pill.orange { background: var(--orl); color: var(--ora); }
.pill.purple { background: var(--prl); color: var(--pur); }
.pill.yellow { background: var(--yll); color: var(--yel); }
.pill.gray   { background: var(--bg3); color: var(--txt3); }
.role-chip { display: inline-flex; align-items: center; gap: 3px; padding: 2px 7px; border-radius: 4px; font-size: 10px; font-weight: 600; letter-spacing: .2px; text-transform: uppercase; }
.role-chip.superadmin { background: var(--prl); color: var(--pur); }
.role-chip.admin      { background: var(--acc3); color: var(--acc); }
.role-chip.manager    { background: var(--orl); color: var(--ora); }
.role-chip.supervisor { background: var(--yll); color: var(--yel); }
.role-chip.user       { background: var(--bg3); color: var(--txt3); }
.role-chip.medico     { background: #e0f2fe; color: #0891b2; }

/* ── MODALS ─────────────────────────────────────────────── */
.modal-overlay { position: fixed; inset: 0; background: rgba(0,0,0,.45); display: flex; align-items: center; justify-content: center; z-index: 500; opacity: 0; pointer-events: none; transition: opacity var(--transition); padding: 16px; }
.modal-overlay.open { opacity: 1; pointer-events: all; }
.modal { background: var(--bg1); border-radius: var(--rad3); box-shadow: var(--shadow2); width: min(560px, 95vw); max-height: calc(100vh - 32px); display: flex; flex-direction: column; border: 1px solid var(--brd); transform: translateY(8px); transition: transform var(--transition); }
.modal-overlay.open .modal { transform: translateY(0); }
.modal-header { padding: 18px 22px 14px; display: flex; align-items: center; gap: 10px; border-bottom: 1px solid var(--brd); flex-shrink: 0; }
.modal-title { font-size: 15px; font-weight: 600; color: var(--txt1); flex: 1; }
.modal-body { padding: 20px 22px; overflow-y: auto; flex: 1; min-height: 0; }
.modal-footer { padding: 14px 22px; border-top: 1px solid var(--brd); display: flex; justify-content: flex-end; gap: 8px; flex-shrink: 0; }
.close-btn { background: none; border: none; cursor: pointer; color: var(--txt3); font-size: 18px; display: flex; padding: 3px; border-radius: 6px; transition: color var(--transition), background var(--transition); }
.close-btn:hover { color: var(--txt1); background: var(--bg2); }

/* ── DROPDOWNS ──────────────────────────────────────────── */
.dropdown { position: relative; }
.dropdown-menu { position: absolute; top: calc(100% + 6px); right: 0; background: var(--bg1); border: 1px solid var(--brd); border-radius: var(--rad2); box-shadow: var(--shadow2); min-width: 200px; z-index: 300; overflow: hidden; opacity: 0; transform: translateY(-6px); pointer-events: none; transition: opacity var(--transition), transform var(--transition); }
.dropdown-menu.open { opacity: 1; transform: translateY(0); pointer-events: all; }
.dd-header { padding: 12px 14px 10px; border-bottom: 1px solid var(--brd); }
.dd-user-name { font-size: 13px; font-weight: 600; color: var(--txt1); }
.dd-user-role { font-size: 11px; color: var(--txt3); margin-top: 1px; }
.dd-item { padding: 9px 14px; font-size: 13px; color: var(--txt2); cursor: pointer; display: flex; align-items: center; gap: 9px; transition: background var(--transition); background: none; border: none; width: 100%; text-align: left; font-family: var(--font); text-decoration: none; }
.dd-item:hover { background: var(--bg2); color: var(--txt1); text-decoration: none; }
.dd-item.danger { color: var(--red); }
.dd-item.danger:hover { background: var(--rdl); }
.dd-sep { height: 1px; background: var(--brd); margin: 4px 0; }
.dd-item .ti { font-size: 15px; color: var(--txt3); }
.dd-item.danger .ti { color: var(--red); }

/* ── TABS ───────────────────────────────────────────────── */
.tabs { display: flex; gap: 0; border-bottom: 1px solid var(--brd); margin-bottom: 18px; }
.tab { padding: 9px 16px; font-size: 13px; font-weight: 400; color: var(--txt3); cursor: pointer; border-bottom: 2px solid transparent; transition: color var(--transition), border-color var(--transition); white-space: nowrap; background: none; border-top: none; border-left: none; border-right: none; font-family: var(--font); }
.tab.active { color: var(--acc); font-weight: 500; border-bottom-color: var(--acc); }
.tab:hover:not(.active) { color: var(--txt2); }

/* ── TOASTS ─────────────────────────────────────────────── */
.toast-container { position: fixed; bottom: 20px; right: 20px; z-index: 9999; display: flex; flex-direction: column; gap: 8px; pointer-events: none; }
.toast { padding: 11px 16px; border-radius: var(--rad2); font-size: 13px; font-weight: 500; display: flex; align-items: center; gap: 10px; box-shadow: var(--shadow2); animation: slideInToast .2s ease; max-width: 340px; pointer-events: all; }
.toast.info    { background: var(--acc);  color: #fff; }
.toast.success { background: var(--grn);  color: #fff; }
.toast.error   { background: var(--red);  color: #fff; }
.toast.warning { background: var(--ora);  color: #fff; }
@keyframes slideInToast { from { transform: translateX(100%); opacity: 0; } to { transform: translateX(0); opacity: 1; } }

/* ── TREE (org structure) ───────────────────────────────── */
.tree-node { padding: 4px 0 4px 18px; position: relative; }
.tree-node::before { content: ''; position: absolute; left: 6px; top: 0; bottom: 0; border-left: 1px dashed var(--brd); }
.tree-node:last-child::before { height: 18px; }
.tree-item { display: inline-flex; align-items: center; gap: 7px; padding: 5px 10px; border: 1px solid var(--brd); border-radius: var(--rad); background: var(--bg1); font-size: 12px; cursor: pointer; transition: border-color var(--transition), background var(--transition); font-family: var(--font); color: var(--txt2); }
.tree-item:hover, .tree-item.active { border-color: var(--acc); background: var(--acc3); color: var(--acc); }
.tree-item .ti { font-size: 14px; }

/* ── UTILITY ────────────────────────────────────────────── */
.flex { display: flex; }
.flex-col { flex-direction: column; }
.items-center { align-items: center; }
.flex-wrap { flex-wrap: wrap; }
.gap-1 { gap: 4px; }
.gap-2 { gap: 8px; }
.gap-3 { gap: 12px; }
.gap-4 { gap: 16px; }
.mt-1 { margin-top: 4px; }
.mt-2 { margin-top: 8px; }
.mt-3 { margin-top: 12px; }
.mt-4 { margin-top: 16px; }
.mb-2 { margin-bottom: 8px; }
.ml-auto { margin-left: auto; }
.w-full { width: 100%; }
.text-sm { font-size: 12px; }
.text-xs { font-size: 11px; }
.text-muted { color: var(--txt3); }
.fw-5 { font-weight: 500; }
.fw-6 { font-weight: 600; }
.text-center { text-align: center; }
.text-acc { color: var(--acc); }
.text-grn { color: var(--grn); }
.text-red { color: var(--red); }
.hidden { display: none !important; }
.mono { font-family: var(--mono); }

/* ── SCROLLBAR ──────────────────────────────────────────── */
::-webkit-scrollbar { width: 5px; height: 5px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: var(--brd2); border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: var(--txt3); }

/* ── RESPONSIVE ─────────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar: 0px; }
  .topbar-search { display: none; }
  .company-switcher { min-width: 140px; max-width: 180px; }
  .sidebar { position: fixed; left: -260px; top: var(--topbar); height: calc(100vh - var(--topbar)); width: 260px; z-index: 200; transition: left var(--transition); box-shadow: var(--shadow2); }
  .sidebar.mobile-open { left: 0; }
  #mobileMenuBtn { display: flex !important; }
  .content { padding: 0 14px 24px; }
  .page-header { padding: 10px 0 10px; flex-wrap: wrap; }
  .stats-grid { grid-template-columns: repeat(2, 1fr); }
}

@media (max-width: 480px) {
  .stats-grid { grid-template-columns: 1fr; }
  .form-grid { grid-template-columns: 1fr; }
  .ph-actions { width: 100%; }
}



/* ── Mantenimiento: grid de cards ─────────────────── */
.maint-grid {
  display: grid;
  grid-template-columns: repeat(3, 1fr);
  gap: 16px;
  margin-top: 8px;
}
@media (max-width: 900px)  { .maint-grid { grid-template-columns: repeat(2, 1fr); } }
@media (max-width: 560px)  { .maint-grid { grid-template-columns: 1fr; } }

.team-card {
  background: var(--bg1);
  border: 0.5px solid var(--brd);
  border-radius: 12px;
  overflow: hidden;
  display: flex;
  flex-direction: column;
}
.team-card-header {
  padding: 16px 18px 12px;
  display: flex;
  align-items: flex-start;
  gap: 12px;
  border-bottom: 1px solid var(--brd);
}
.team-avatar {
  width: 44px; height: 44px; border-radius: 10px;
  display: flex; align-items: center; justify-content: center; flex-shrink: 0;
}
.team-info { flex: 1; min-width: 0; }
.team-name {
  font-size: 14px; font-weight: 600; color: var(--txt1); margin-bottom: 2px;
  white-space: nowrap; overflow: hidden; text-overflow: ellipsis;
}
.team-leader { font-size: 12px; color: var(--txt3); }
.team-card-body { padding: 12px 18px; flex: 1; }
.team-desc {
  font-size: 12px; color: var(--txt3); line-height: 1.5; margin-bottom: 12px;
  display: -webkit-box; -webkit-line-clamp: 2; -webkit-box-orient: vertical;
  overflow: hidden; min-height: 36px;
}
.team-stats { display: flex; gap: 16px; flex-wrap: wrap; }
.team-stat { display: flex; align-items: center; gap: 5px; font-size: 12px; color: var(--txt3); }
.team-stat strong { color: var(--txt1); font-size: 15px; font-weight: 600; }
.team-card-footer {
  padding: 10px 14px;
  border-top: 1px solid var(--brd);
  display: flex;
  align-items: center;
  justify-content: center;
  gap: 6px;
  background: var(--bg2);
  flex-wrap: wrap;
}

/* Badge aliases for maintenance module */
.badge-success { background: var(--gnl); color: var(--grn); display:inline-flex; align-items:center; padding:2px 8px; border-radius:20px; font-size:11px; font-weight:600; white-space:nowrap; }
.badge-gray    { background: var(--bg3); color: var(--txt3); display:inline-flex; align-items:center; padding:2px 8px; border-radius:20px; font-size:11px; font-weight:600; white-space:nowrap; }
.badge-warn    { background: var(--orl); color: var(--ora); display:inline-flex; align-items:center; padding:2px 8px; border-radius:20px; font-size:11px; font-weight:600; white-space:nowrap; }
.badge-info    { background: var(--acc3); color: var(--acc); display:inline-flex; align-items:center; padding:2px 8px; border-radius:20px; font-size:11px; font-weight:600; white-space:nowrap; }

/* Sortable table headers */
table.table thead th[data-col] { cursor: pointer; white-space: nowrap; }
table.table thead th[data-col]:hover { background: var(--bg3); }
table.table thead th[data-dir="asc"],
table.table thead th[data-dir="desc"] { color: var(--acc); }

/* ── Contraste automático en fondos oscuros ──────────────── */
/* Cuando un td/th/div/span tiene background #4A5568 (gris-slate oscuro),
   el texto se fuerza a blanco para garantizar legibilidad.
   Clase helper .dark-bg para uso programático. */
[style*="background:#4A5568"],
[style*="background: #4A5568"],
[style*="background-color:#4A5568"],
[style*="background-color: #4A5568"],
.dark-bg {
    color: #ffffff !important;
}
/* Excepción: cuando el elemento recupera su bg normal al quitar hover
   de la fila, el color original se restaura vía JS (ver app.js). */

/* ══════════════════════════════════════════════════════════
   RESPONSIVIDAD MÓVIL — quoERP
   Breakpoints: 768px (tablet), 480px (mobile)
   ══════════════════════════════════════════════════════════ */

/* ── Contenido principal: padding en mobile ───────────────── */
@media (max-width: 768px) {
  /* Wrapper de contenido: padding reducido en tablet/mobile */
  .page-content { padding: 12px 14px 32px; }
}

/* ── Layout general ───────────────────────────────────────── */
@media (max-width: 768px) {
  :root { --sidebar: 0px; }

  /* Sidebar: se desliza como drawer desde la izquierda */
  .sidebar {
    position: fixed;
    left: -280px;
    top: var(--topbar);
    height: calc(100vh - var(--topbar));
    width: 280px;
    z-index: 300;
    transition: left .25s ease;
    box-shadow: var(--shadow2);
  }
  .sidebar.mobile-open { left: 0; }
  #mobileMenuBtn { display: flex !important; }

  /* Overlay oscuro cuando el sidebar está abierto */
  .sidebar-overlay {
    display: none;
    position: fixed;
    inset: 0;
    top: var(--topbar);
    background: rgba(0,0,0,.45);
    z-index: 299;
    cursor: pointer;
  }
  .sidebar-overlay.active { display: block; }

  /* Topbar: compactar en mobile */
  .topbar-search { display: none; }
  .company-switcher { min-width: 100px; max-width: 150px; font-size: 11px; padding: 4px 8px; }
  .co-name { font-size: 11px; }
  .co-branch { display: none; }                    /* ocultar subbranch label */
  .topbar-logo .logo-erp { display: none; }        /* ocultar "ERP" en el logo */
  .topbar-logo { min-width: auto; font-size: 15px; }
  .topbar-right { gap: 2px; margin-left: auto; }
  .tb-btn { width: 36px; height: 36px; font-size: 17px; }

  /* Página: header apila en columna */
  .page-header {
    flex-direction: column;
    gap: 8px;
    align-items: flex-start;
    padding: 10px 0;
  }
  /* Contenedor de botones en page-header ocupa todo el ancho */
  .page-header > div:last-child {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    width: 100%;
  }

  /* Cards: sin border-radius extra en mobile */
  .card { border-radius: var(--rad); }

  /* TABLAS: scroll horizontal en todos los cards que contienen tablas */
  .card { overflow-x: auto !important; }
  /* Wrapper de tabla dentro de card: permite scroll horizontal manteniendo estructura */
  .card > table.table { display: block; width: 100%; overflow-x: auto; -webkit-overflow-scrolling: touch; }
  .card > .table-responsive { overflow-x: auto; -webkit-overflow-scrolling: touch; }

  /* GRIDS inline: colapsar a 1 columna */
  div[style*="grid-template-columns"] {
    grid-template-columns: 1fr !important;
  }

  /* Grids de stats/resumen: 2 columnas en tablet (sobreescribe el collapse anterior) */
  .stats-grid { grid-template-columns: repeat(2, 1fr) !important; }

  /* Formularios: form-row apila verticalmente */
  .form-row { flex-direction: column; gap: 0; }
  .form-row .form-group { flex: 1 1 100% !important; min-width: 0 !important; width: 100% !important; }

  /* Modales: ancho casi completo */
  .modal { width: 96vw !important; max-width: 96vw !important; margin: 8px; }
  .modal-overlay { padding: 8px; align-items: flex-start; padding-top: 60px; }

  /* Botones táctiles: mínimo 44px de altura */
  .btn, button, a.btn { min-height: 38px; }
  .btn.sm { min-height: 32px; }

  /* Ocultar columnas de tablas no esenciales */
  .hide-mobile { display: none !important; }

  /* Kanban CRM: scroll horizontal */
  .kanban-col { min-width: 220px; }
}

/* ── Mobile pequeño (< 480px) ────────────────────────────── */
@media (max-width: 480px) {
  /* Stats/KPIs: 1 columna en teléfono */
  .stats-grid,
  div[style*="repeat(3,1fr)"],
  div[style*="repeat(4,1fr)"],
  div[style*="repeat(2,1fr)"],
  div[style*="repeat(3, 1fr)"],
  div[style*="repeat(4, 1fr)"],
  div[style*="repeat(2, 1fr)"] {
    grid-template-columns: 1fr !important;
  }

  /* 2 columnas solo si están explícitamente marcadas */
  .grid-2-mobile { grid-template-columns: repeat(2, 1fr) !important; }

  /* Page sub: ocultar en pantallas muy pequeñas */
  .page-sub { display: none; }

  /* Tablas: fuente más pequeña */
  .table { font-size: 11px !important; }
  .table th, .table td { padding: 6px 8px !important; }

  /* Modales: pantalla completa */
  .modal-overlay { padding: 0; align-items: flex-end; }
  .modal {
    width: 100vw !important;
    max-width: 100vw !important;
    margin: 0;
    border-radius: var(--rad2) var(--rad2) 0 0;
    max-height: 92vh;
  }

  /* Wrapper de contenido en mobile muy pequeño */
  .page-content { padding: 8px 10px 24px; }

  /* Ocultar columnas secundarias en listas */
  .hide-sm { display: none !important; }

  /* Dropdowns: ancho completo */
  .dropdown-menu { right: -8px; min-width: 160px; }

  /* Formularios: labels más compactos */
  .form-label { font-size: 12px; }
  .form-control { font-size: 13px; padding: 8px 10px; }
}

/* ── Mejoras táctiles globales ────────────────────────────── */
@media (hover: none) and (pointer: coarse) {
  /* Dispositivos táctiles: quitar hover effects que quedan pegados */
  .nav-item:active { background: var(--bg2); }
  .btn:active { opacity: .85; }
  /* Aumentar área de toque en links pequeños */
  a, button { -webkit-tap-highlight-color: transparent; }
}

/* ── Dictado por voz ─────────────────────────────────────── */
.dictate-wrap {
  position: relative;
  display: block;
}
.dictate-btn {
  position: absolute;
  top: 6px;
  right: 6px;
  width: 24px;
  height: 24px;
  display: flex;
  align-items: center;
  justify-content: center;
  background: var(--bg2);
  border: 1px solid var(--brd);
  border-radius: 50%;
  cursor: pointer;
  color: var(--txt2);
  padding: 0;
  opacity: .55;
  transition: opacity .15s, color .15s, background .15s, border-color .15s;
  z-index: 2;
}
.dictate-btn:hover {
  opacity: 1;
  color: var(--acc);
  background: var(--bg1);
}
.dictate-btn--active {
  opacity: 1 !important;
  color: #dc2626 !important;
  background: #fee2e2 !important;
  border-color: #fca5a5 !important;
  animation: dictate-pulse 1.1s ease-in-out infinite;
}
@keyframes dictate-pulse {
  0%,100% { box-shadow: 0 0 0 0 rgba(220,38,38,.45); }
  55%     { box-shadow: 0 0 0 5px rgba(220,38,38,0); }
}

/* ── Atajos de teclado — panel ──────────────────────────── */
.shortcuts-modal { width: min(560px, 96vw); }

.sc-group { margin-bottom: 20px; }
.sc-group-label {
  font-size: 10px;
  font-weight: 700;
  letter-spacing: .08em;
  text-transform: uppercase;
  color: var(--txt3);
  margin-bottom: 6px;
  padding-bottom: 4px;
  border-bottom: 1px solid var(--brd);
}
.sc-list { display: flex; flex-direction: column; gap: 1px; }
.sc-item {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 6px 8px;
  border-radius: 6px;
  gap: 12px;
}
.sc-item:hover { background: var(--bg2); }
.sc-label { font-size: 13px; color: var(--txt1); flex: 1; }
.sc-keys  { display: flex; align-items: center; gap: 4px; flex-shrink: 0; }
.sc-then  { font-size: 10px; color: var(--txt3); margin: 0 2px; }

/* Tecla de teclado genérica */
.kbdkey {
  display: inline-flex;
  align-items: center;
  justify-content: center;
  min-width: 24px;
  height: 22px;
  padding: 0 6px;
  font-family: var(--mono);
  font-size: 11px;
  font-weight: 600;
  color: var(--txt2);
  background: var(--bg2);
  border: 1px solid var(--brd2);
  border-bottom-width: 2px;
  border-radius: 5px;
  line-height: 1;
  white-space: nowrap;
}
[data-theme="dark"] .kbdkey {
  background: var(--bg3);
  border-color: var(--brd2);
}

/* ── Tips contextuales — barra flotante ─────────────────── */
.quo-tip-bar {
  position: fixed;
  bottom: 20px;
  left: 50%;
  transform: translateX(-50%) translateY(12px);
  display: flex;
  align-items: center;
  gap: 10px;
  background: var(--txt1);
  color: var(--bg1);
  padding: 10px 14px 10px 12px;
  border-radius: 10px;
  box-shadow: var(--shadow2);
  font-size: 13px;
  line-height: 1.45;
  max-width: min(560px, calc(100vw - 40px));
  z-index: 9990;
  opacity: 0;
  pointer-events: none;
  transition: opacity .28s ease, transform .28s ease;
}
.quo-tip-bar.visible {
  opacity: 1;
  transform: translateX(-50%) translateY(0);
  pointer-events: auto;
}
.quo-tip-icon {
  font-size: 16px;
  color: var(--acc2);
  flex-shrink: 0;
}
[data-theme="dark"] .quo-tip-icon { color: #6ba3e0; }
.quo-tip-text { flex: 1; }
.quo-tip-text .kbdkey {
  background: rgba(255,255,255,.15);
  border-color: rgba(255,255,255,.25);
  color: #fff;
}
.quo-tip-close {
  flex-shrink: 0;
  width: 22px;
  height: 22px;
  display: flex;
  align-items: center;
  justify-content: center;
  border: none;
  background: rgba(255,255,255,.12);
  border-radius: 4px;
  cursor: pointer;
  color: inherit;
  font-size: 13px;
  transition: background var(--transition);
}
.quo-tip-close:hover { background: rgba(255,255,255,.22); }

/* Toggle switch (para preferencias de UI en el perfil) */
.ui-toggle {
  display: flex;
  align-items: center;
  justify-content: space-between;
  padding: 10px 0;
  border-bottom: 1px solid var(--brd);
}
.ui-toggle:last-child { border-bottom: none; }
.ui-toggle-info { flex: 1; }
.ui-toggle-title { font-size: 13px; font-weight: 600; color: var(--txt1); }
.ui-toggle-desc  { font-size: 12px; color: var(--txt3); margin-top: 1px; }
.toggle-switch {
  position: relative;
  width: 38px;
  height: 22px;
  flex-shrink: 0;
  margin-left: 16px;
}
.toggle-switch input { opacity: 0; width: 0; height: 0; position: absolute; }
.toggle-track {
  position: absolute;
  inset: 0;
  border-radius: 22px;
  background: var(--brd2);
  cursor: pointer;
  transition: background var(--transition);
}
.toggle-switch input:checked + .toggle-track { background: var(--acc); }
.toggle-track::after {
  content: '';
  position: absolute;
  top: 3px;
  left: 3px;
  width: 16px;
  height: 16px;
  border-radius: 50%;
  background: #fff;
  transition: transform var(--transition);
  box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle-switch input:checked + .toggle-track::after { transform: translateX(16px); }

/* ═══════════════════════════════════════════════════════════
   ACCESIBILIDAD — preferencias de usuario (perfil)
   Se aplican por atributo en <html>; funcionan en el shell y en
   los iframes de tabs (ambos cargan este mismo app.css).
   ═══════════════════════════════════════════════════════════ */

/* Reducir movimiento: desactiva animaciones y transiciones */
html[data-reduce-motion="1"] *,
html[data-reduce-motion="1"] *::before,
html[data-reduce-motion="1"] *::after {
  animation-duration: .001ms !important;
  animation-iteration-count: 1 !important;
  transition-duration: .001ms !important;
  scroll-behavior: auto !important;
}

/* Alto contraste: refuerza textos tenues, bordes y foco (light + dark) */
html[data-contrast="high"] {
  --txt2: #1a1f26;
  --txt3: #3a4450;
  --brd:  #7a8595;
  --brd2: #55606e;
}
html[data-contrast="high"][data-theme="dark"] {
  --txt1: #ffffff;
  --txt2: #d6dde4;
  --txt3: #a7b0ba;
  --brd:  #6e7a88;
  --brd2: #8a95a2;
}
html[data-contrast="high"] a { text-decoration: underline; }
html[data-contrast="high"] :focus-visible {
  outline: 2px solid var(--acc) !important;
  outline-offset: 2px !important;
}
