/* =====================================================================
   cloud / style.css
   Sistema de diseno unico para toda la app. Ver DESIGN.md.
   ===================================================================== */

/* 1. Tokens */
:root {
  --bg:        #1a1a1a;
  --surface:   #242526;
  --border:    #383838;
  --row-hover: #2d2e2f;
  --primary:   #317535;
  --primary-h: #245828;
  --danger:    #e62a2a;
  --success:   #22c55e;
  --warn:      #f59e0b;
  --info:      #3b82f6;
  --purple:    #8b5cf6;
  --text:      #f0f0f0;
  --muted:     #9ca0a4;
  --radius:    10px;
  --shadow:    0 1px 4px rgba(0,0,0,.45);
  --shadow-lg: 0 8px 32px rgba(0,0,0,.65);
}

/* 2. Reset & base */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }
body {
  font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', sans-serif;
  background: var(--bg); color: var(--text); min-height: 100vh;
}
a { color: inherit; text-decoration: none; }

/* 3. Layout */
.layout  { display: flex; min-height: 100vh; }
.sidebar { width: 220px; background: var(--primary);
           border-right: 1px solid rgba(0,0,0,.25);
           display: flex; flex-direction: column; flex-shrink: 0; }
.main    { flex: 1; display: flex; flex-direction: column; overflow: hidden; min-width: 0; }
.topbar  { background: var(--primary);
           border-bottom: 1px solid rgba(0,0,0,.25);
           padding: 0 24px; height: 60px;
           display: flex; align-items: center; justify-content: space-between;
           box-shadow: var(--shadow); position: relative; }
.content { flex: 1; padding: 24px; overflow-y: auto; }

/* 4. Sidebar */
.sidebar-logo       { height: 60px; padding: 0 20px;
                      border-bottom: 1px solid rgba(0,0,0,.2);
                      display: flex; align-items: center; justify-content: center;
                      flex-shrink: 0; }
.sidebar-logo-mark  { display: block; width: auto; height: 24px;
                      max-width: 100%; object-fit: contain; }
.sidebar-nav        { padding: 8px 0 12px; flex: 1; }
.sidebar-footer     { padding: 10px 20px; font-size: .75rem; color: rgba(255,255,255,.7);
                      border-top: 1px solid rgba(0,0,0,.2); text-align: center;
                      letter-spacing: .03em; font-family: monospace; }

.nav-item { display: flex; align-items: center; gap: 10px;
            padding: 10px 20px; font-size: .9rem; color: rgba(255,255,255,.85);
            cursor: pointer; border-left: 3px solid transparent;
            transition: background .15s, color .15s; text-decoration: none; }
.nav-item:hover  { background: rgba(0,0,0,.18); color: #fff; }
.nav-item.active { background: rgba(0,0,0,.28); color: #fff;
                   border-left-color: #fff; font-weight: 600; }
.nav-icon { font-size: 1.1rem; width: 20px; text-align: center; }

/* Grupos colapsables del sidebar (DESIGN.md §4) */
.nav-group-wrap                       { display: block; }
.nav-group-toggle                     { width: 100%; background: none; border: none;
                                        text-align: left; cursor: pointer;
                                        font-family: inherit; color: rgba(255,255,255,.85); }
.nav-group-label                      { flex: 1; }
.nav-group-arrow                      { margin-left: auto; font-size: 1rem; font-weight: 700;
                                        line-height: 1; color: rgba(255,255,255,.7);
                                        transition: transform .2s; }
.nav-group-wrap.open .nav-group-arrow { transform: rotate(45deg); }
.nav-sub                              { display: none; background: rgba(0,0,0,.18);
                                        border-top: 1px solid rgba(0,0,0,.2);
                                        border-bottom: 1px solid rgba(0,0,0,.2); }
.nav-group-wrap.open .nav-sub         { display: block; }
.nav-sub-item                         { padding-left: 44px; font-size: .85rem; }
.nav-sub-item.active                  { background: rgba(0,0,0,.32); }

/* 5. Topbar */
.topbar-title    { font-size: 1rem; font-weight: 600; flex: 1; color: #fff; }
.topbar-user     { display: flex; align-items: center; gap: 10px; flex-shrink: 0;
                   position: relative; }
.topbar-username { background: none; border: none; cursor: pointer;
                   font-size: .85rem; color: rgba(255,255,255,.85);
                   display: flex; align-items: center; gap: 4px;
                   padding: 6px 10px; border-radius: 8px;
                   transition: background .15s, color .15s; font-family: inherit; }
.topbar-username:hover { background: rgba(0,0,0,.18); color: #fff; }

.topbar .hamburger { color: #fff; }

.user-dropdown   { display: none; position: absolute; right: 0; top: calc(100% + 6px);
                   background: var(--surface); border: 1px solid var(--border);
                   border-radius: 10px; box-shadow: var(--shadow-lg);
                   min-width: 180px; overflow: hidden; z-index: 200; }
.user-dropdown.open { display: block; }
.user-dropdown .action-menu-item { display: flex; align-items: center; gap: 10px; width: 100%;
                                   padding: 10px 16px; font-size: .85rem; color: var(--text);
                                   background: none; border: none; cursor: pointer;
                                   text-align: left; font-family: inherit; }
.user-dropdown .action-menu-item:hover:not(:disabled) { background: var(--bg); color: var(--primary); }
.user-dropdown .action-menu-item:disabled { opacity: .5; cursor: not-allowed; }
.user-dropdown .action-menu-item i { width: 16px; text-align: center; color: var(--muted); }

/* 6. Botones */
.btn { padding: 8px 16px; border-radius: var(--radius); border: none;
       font-size: .88rem; font-weight: 600; cursor: pointer;
       display: inline-flex; align-items: center; gap: 6px;
       transition: background .15s, transform .1s; font-family: inherit; }
.btn:active        { transform: scale(.97); }
.btn-primary       { background: var(--primary); color: #fff; }
.btn-primary:hover { background: var(--primary-h); }
.btn-danger        { background: var(--danger); color: #fff; }
.btn-danger:hover  { background: #c91515; }
.btn-secondary     { background: var(--surface); color: var(--text);
                     border: 1px solid var(--border); }
.btn-secondary:hover { background: var(--bg); }
.btn:disabled, .btn[disabled] { opacity: .5; cursor: not-allowed; }
.btn:disabled:hover           { background: inherit; }
.btn-ghost         { background: transparent; color: var(--muted);
                     border: 1px solid var(--border); }
.btn-ghost:hover   { background: var(--bg); color: var(--text); }
.btn-sm            { padding: 5px 12px; font-size: .8rem; }
.btn-icon-sm       { background: none; border: none; cursor: pointer;
                     padding: 4px 8px; border-radius: 6px; font-size: .85rem;
                     color: var(--muted); font-family: inherit; }
.btn-icon-sm:hover { background: var(--bg); color: var(--text); }

/* 10. Tablas */
.table-card { background: var(--surface); border: 1px solid var(--border);
              border-radius: var(--radius); box-shadow: var(--shadow);
              overflow-x: auto; overflow-y: hidden; }
table       { width: 100%; border-collapse: collapse; font-size: .88rem; }
thead tr    { background: var(--bg); }
th          { padding: 10px 14px; text-align: left;
              font-size: .75rem; text-transform: uppercase; letter-spacing: .05em;
              color: var(--muted); font-weight: 600;
              border-bottom: 1px solid var(--border); white-space: nowrap; }
td          { padding: 10px 14px; border-bottom: 1px solid var(--border);
              vertical-align: middle; }
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--row-hover); }
.td-nombre  { font-weight: 600; }
.td-id      { color: var(--muted); font-size: .8rem; }
.table-empty { text-align: center; padding: 48px 24px; color: var(--muted); }

/* 11. Badges */
.badge         { display: inline-block; padding: 2px 10px;
                 border-radius: 99px; font-size: .75rem; font-weight: 600; }
.badge-info    { background: rgba(59,130,246,.18); color: #93c5fd; }
.badge-success { background: rgba(34,197,94,.18);  color: #86efac; }
.badge-danger  { background: rgba(230,42,42,.2);   color: #f5a8a8; }
.badge-warn    { background: rgba(245,158,11,.18); color: #fcd34d; }

/* 12. Stat cards */
.stats-bar  { display: flex; gap: 14px; margin-bottom: 20px; flex-wrap: wrap; }
.stat-card  { background: var(--surface); border: 1px solid var(--border);
              border-radius: var(--radius); padding: 14px 20px;
              display: flex; flex-direction: column; gap: 2px;
              flex: 1; min-width: 140px; }
.stat-label { font-size: .75rem; color: var(--muted);
              text-transform: uppercase; letter-spacing: .04em; }
.stat-value { font-size: 1.5rem; font-weight: 700; }
.stat-value.green  { color: var(--success); }
.stat-value.orange { color: var(--primary); }
.stat-value.red    { color: var(--danger); }
.stat-value.blue   { color: var(--info); }

.dash-link { cursor: pointer; transition: opacity .15s; }
.dash-link:hover { opacity: .75; }
.stat-card.dash-link:hover { background: var(--bg); }

/* 13. Dashboard grid */
.dash-grid { display: grid; grid-template-columns: 1fr 1fr; gap: 20px; margin-top: 4px; }
.dash-table-header { padding: 14px 20px 10px;
                     font-weight: 600; font-size: .95rem;
                     border-bottom: 1px solid var(--border);
                     display: flex; align-items: center; justify-content: space-between; }
.dash-ver-mas      { font-size: .78rem; font-weight: 500; color: var(--primary); cursor: pointer; }
.dash-ver-mas:hover { text-decoration: underline; }

/* 18. Spinner */
.spin { display: inline-block; width: 28px; height: 28px;
        border: 3px solid var(--border); border-top-color: var(--primary);
        border-radius: 50%; animation: spin .7s linear infinite; }
@keyframes spin { to { transform: rotate(360deg); } }

/* 19. Responsive */
.hamburger        { display: none; background: none; border: none; cursor: pointer;
                    font-size: 1.4rem; color: var(--text);
                    padding: 4px 8px; margin-right: 8px; line-height: 1; }
.sidebar-overlay  { display: none; position: fixed; inset: 0;
                    background: rgba(0,0,0,.45); z-index: 199; }
.sidebar-overlay.active { display: block; }

@media (max-width: 768px) {
  .hamburger { display: inline-flex; align-items: center; }
  .sidebar   { position: fixed; top: 0; left: 0; height: 100vh; z-index: 200;
               transform: translateX(-100%); transition: transform .25s; }
  .sidebar.open { transform: translateX(0); }
  .dash-grid { grid-template-columns: 1fr; }
  .form-row, .form-row-3, .form-row-4 { grid-template-columns: 1fr; }
}

/* 7. Inputs, selects, textareas */
input[type=text], input[type=number], input[type=url], input[type=tel],
input[type=email], input[type=date], input[type=time], input[type=datetime-local],
input[type=password], input[type=search], select, textarea {
  border: 1px solid var(--border); border-radius: var(--radius);
  padding: 8px 12px; font-size: .88rem; background: var(--surface);
  color: var(--text); outline: none; transition: border .15s; font-family: inherit;
}
input:focus, select:focus, textarea:focus {
  border-color: var(--primary); box-shadow: 0 0 0 3px rgba(49,117,53,.25);
}
input:disabled, select:disabled, textarea:disabled,
input[readonly], textarea[readonly] {
  color: var(--muted); background: var(--bg); cursor: not-allowed; opacity: .75;
}
textarea { resize: vertical; min-height: 60px; }

.field-error   { margin-top: 4px; font-size: .78rem; color: var(--danger); }
.input-invalid { border-color: var(--danger) !important;
                 box-shadow: 0 0 0 2px rgba(239,68,68,.18); }

/* 8. Formularios */
.form-row    { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.form-row-3  { display: grid; grid-template-columns: repeat(3, 1fr); gap: 12px; }
.form-row-4  { display: grid; grid-template-columns: repeat(4, 1fr); gap: 12px; }
.form-group  { display: flex; flex-direction: column; gap: 5px; }
.form-group label {
  font-size: .8rem; font-weight: 600; color: var(--muted);
}
.form-group input,
.form-group select,
.form-group textarea { width: 100%; }

/* 9. Toolbar */
.toolbar       { display: flex; align-items: center; gap: 12px;
                 flex-wrap: wrap; margin-bottom: 20px; }
.toolbar-left  { display: flex; align-items: center; gap: 10px;
                 flex: 1; flex-wrap: wrap; }
.toolbar-right { display: flex; gap: 10px; }

.search-wrap        { position: relative; display: inline-flex; align-items: center; }
.search-wrap .search-input { width: 240px; padding-right: 28px; }
.search-clear       { position: absolute; right: 6px; background: none; border: none;
                      cursor: pointer; color: var(--muted); font-size: 1.1rem;
                      padding: 2px 4px; border-radius: 50%; transition: color .15s; }
.search-clear:hover { color: var(--text); }

.filter-chip        { padding: 6px 12px; border-radius: 20px;
                      border: 1.5px solid var(--border);
                      font-size: .8rem; font-weight: 600; cursor: pointer;
                      white-space: nowrap; background: var(--surface);
                      color: var(--muted); transition: all .15s;
                      font-family: inherit; }
.filter-chip:hover  { border-color: var(--primary); color: var(--primary); }
.filter-chip.active { background: var(--primary); border-color: var(--primary); color: #fff; }

/* Encabezado de modulo (titulo + subtitulo de pagina) */
.page-header   { margin-bottom: 20px; }
.page-title    { font-size: 1.4rem; font-weight: 700; color: var(--text); }
.page-subtitle { margin-top: 4px; font-size: .88rem; color: var(--muted); }

/* Acciones de fila (iconos de la columna Acciones) */
.actions          { display: flex; gap: 6px; align-items: center; }
.action-icon      { background: none; border: none; cursor: pointer;
                    padding: 6px 8px; border-radius: 6px; color: var(--muted);
                    font-size: .95rem; transition: background .15s, color .15s;
                    font-family: inherit; }
.action-icon:hover           { background: var(--bg); color: var(--text); }
.action-icon.view:hover      { color: var(--info); }
.action-icon.edit:hover      { color: var(--primary); }
.action-icon.delete:hover    { color: var(--danger); }
.action-icon:disabled,
.action-icon[disabled]       { opacity: .4; cursor: not-allowed; }
.action-icon:disabled:hover  { background: none; color: var(--muted); }

/* 14. Modales */
.modal-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.45);
                  display: flex; align-items: center; justify-content: center;
                  z-index: 100; opacity: 0; pointer-events: none; transition: opacity .2s; }
.modal-backdrop.open { opacity: 1; pointer-events: all; }
.modal          { background: var(--surface); border-radius: 14px;
                  width: 100%; max-width: 520px; max-height: 90vh; overflow-y: auto;
                  box-shadow: var(--shadow-lg);
                  transform: scale(.96) translateY(12px); transition: transform .2s; margin: 16px; }
.modal-backdrop.open .modal { transform: scale(1) translateY(0); }
.modal-header   { padding: 20px 24px 16px; border-bottom: 1px solid var(--border);
                  display: flex; align-items: center; justify-content: space-between; }
.modal-title    { font-size: 1rem; font-weight: 700;
                  display: flex; align-items: baseline; gap: 10px; flex-wrap: wrap; }
.modal-subtitle { font-size: .8rem; font-weight: 500; color: var(--muted); }
.modal-body     { padding: 20px 24px; display: flex; flex-direction: column; gap: 16px; }
.modal-footer   { padding: 16px 24px; border-top: 1px solid var(--border);
                  display: flex; gap: 10px; justify-content: flex-end; align-items: center; }
.modal.modal-wide { max-width: 760px; }

/* 15. Confirm dialog */
.confirm-backdrop { position: fixed; inset: 0; background: rgba(0,0,0,.5);
                    display: flex; align-items: center; justify-content: center;
                    z-index: 150; opacity: 0; pointer-events: none; transition: opacity .15s; }
.confirm-backdrop.open { opacity: 1; pointer-events: all; }
.confirm-box     { background: var(--surface); border-radius: 14px;
                   padding: 28px 28px 20px; max-width: 380px;
                   width: calc(100% - 32px); box-shadow: var(--shadow-lg);
                   transform: scale(.95); transition: transform .15s; }
.confirm-backdrop.open .confirm-box { transform: scale(1); }
.confirm-title   { font-weight: 700; margin-bottom: 8px; }
.confirm-msg     { font-size: .88rem; color: var(--muted); margin-bottom: 20px; }
.confirm-actions { display: flex; gap: 10px; justify-content: flex-end; }

/* 22. Lista de datos (Consultar) */
.data-list  { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }
.data-row   { background: color-mix(in srgb, var(--surface) 90%, #000);
              border-radius: var(--radius); padding: 12px 14px;
              display: flex; flex-direction: column; gap: 4px; border: none; }
.data-row.full   { grid-column: 1 / -1; }
.data-label      { font-size: .72rem; font-weight: 600;
                   text-transform: uppercase; letter-spacing: .04em; color: var(--muted); }
.data-value      { font-size: .9rem; color: var(--text);
                   word-break: break-word; white-space: pre-wrap; }
.data-value.muted{ color: var(--muted); font-style: italic; }
.data-value code { font-family: monospace; font-size: .85rem;
                   background: var(--bg); border: 1px solid var(--border);
                   border-radius: 6px; padding: 2px 8px; }
@media (max-width: 768px) {
  .data-list { grid-template-columns: 1fr; }
}

/* 24. Tile grid (menu de navegacion / lanzadores) */
.tile-grid  { display: grid;
              grid-template-columns: repeat(auto-fill, minmax(220px, 1fr));
              gap: 16px; }
.tile-card  { background: var(--surface); border: 1px solid var(--border);
              border-radius: var(--radius); padding: 20px;
              display: flex; flex-direction: column; gap: 6px;
              text-align: left; cursor: pointer; text-decoration: none;
              color: var(--text); font-family: inherit;
              transition: border-color .15s, background .15s, transform .1s; }
.tile-card:hover  { border-color: var(--primary); background: var(--row-hover); }
.tile-card:active { transform: scale(.98); }
.tile-icon  { font-size: 1.6rem; line-height: 1; margin-bottom: 4px; }
.tile-title { font-weight: 600; font-size: .95rem; color: var(--text); }
.tile-desc  { font-size: .8rem; color: var(--muted); }

/* 16. Toasts */
.toast { position: fixed; bottom: 24px; left: 50%;
         transform: translateX(-50%) translateY(16px);
         background: #0d0d0d; color: var(--text);
         border: 1px solid var(--border);
         padding: 10px 20px; border-radius: 99px;
         font-size: .88rem; opacity: 0; pointer-events: none;
         transition: opacity .2s, transform .2s;
         z-index: 200; white-space: nowrap;
         box-shadow: var(--shadow-lg); }
.toast.show  { opacity: 1; transform: translateX(-50%) translateY(0); }
.toast.error { background: var(--danger); border-color: var(--danger); color: #fff; }

/* ---- Auth: splash + login ---- */
.auth-checking .layout,
.auth-checking .login-screen,
.is-app .login-screen,
.is-app .auth-splash,
.is-login .layout,
.is-login .auth-splash { display: none !important; }

.auth-splash { position: fixed; inset: 0; display: flex;
               align-items: center; justify-content: center;
               background: var(--bg); z-index: 300; }

.login-screen { position: fixed; inset: 0; display: flex;
                align-items: center; justify-content: center;
                background: var(--bg); padding: 20px; z-index: 250; }

.login-card { width: 100%; max-width: 360px;
              background: var(--surface); border: 1px solid var(--border);
              border-radius: 14px; padding: 28px 24px;
              box-shadow: var(--shadow-lg);
              display: flex; flex-direction: column; gap: 14px; }

.login-logo  { width: 56px; height: 56px; object-fit: contain;
               margin: 0 auto 4px; }
.login-title { text-align: center; font-size: 1.05rem;
               font-weight: 600; color: var(--text); margin-bottom: 6px; }
.login-submit { margin-top: 6px; padding: 10px 16px; font-size: .95rem; }
.login-submit:disabled { opacity: .65; cursor: not-allowed; }

/* ---- Lista de permisos (ABM de Roles) ---- */
.perm-toolbar { display: flex; gap: 8px; align-items: center; flex-wrap: wrap;
                margin-bottom: 8px; }
.perm-list    { border: 1px solid var(--border); border-radius: var(--radius);
                background: var(--bg); max-height: 280px; overflow-y: auto; }
.perm-item    { display: flex; align-items: center; gap: 10px;
                padding: 8px 12px; border-bottom: 1px solid var(--border);
                cursor: pointer; transition: background .15s; }
.perm-item:last-child { border-bottom: none; }
.perm-item:hover      { background: var(--row-hover); }
.perm-check   { width: 16px; height: 16px; accent-color: var(--primary);
                cursor: pointer; flex-shrink: 0; }
.perm-text    { flex: 1; display: flex; flex-direction: column; gap: 2px;
                min-width: 0; }
.perm-name    { font-size: .88rem; color: var(--text); font-weight: 500; }
.perm-desc    { font-size: .78rem; color: var(--muted); }
.perm-id      { font-family: monospace; font-size: .75rem; color: var(--muted);
                flex-shrink: 0; }

