/* ═══════════════════════════════════════════════
   ABUELA CANALLA — ERP OBRADOR
   Design System v2
═══════════════════════════════════════════════ */

@import url('https://fonts.googleapis.com/css2?family=DM+Sans:wght@300;400;500;600;700&display=swap');

@font-face {
    font-family: 'Ovsyanka';
    src: url('../fonts/Ovsyanka.ttf') format('truetype');
    font-weight: normal;
}
@font-face {
    font-family: 'Ovsyanka';
    src: url('../fonts/Ovsyanka-press.ttf') format('truetype');
    font-weight: bold;
}

:root {
    --ac-red:       #e51134;
    --ac-red-dark:  #c00e2b;
    --ac-cream:     #fee9d9;
    --ac-green:     #198754;
    --ac-white:     #ffffff;
    --ac-black:     #1f2937;
    --ac-gray-50:   #f9fafb;
    --ac-gray-100:  #f3f4f6;
    --ac-gray-200:  #e5e7eb;
    --ac-gray-400:  #9ca3af;
    --ac-gray-600:  #4b5563;

    --sidebar-w:    240px;
    --sidebar-collapsed: 64px;
    --topbar-h:     60px;

    --radius:       8px;
    --radius-lg:    12px;
    --shadow:       0 1px 3px rgba(0,0,0,.08), 0 1px 2px rgba(0,0,0,.05);
    --shadow-md:    0 4px 12px rgba(0,0,0,.1);
}

*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

html { font-size: 15px; }

body {
    font-family: 'DM Sans', sans-serif;
    background: var(--ac-gray-50);
    color: var(--ac-black);
    line-height: 1.55;
    -webkit-font-smoothing: antialiased;
}

/* ── LAYOUT ─────────────────────────────────────── */
.app-layout {
    display: flex;
    min-height: 100vh;
}

/* ── SIDEBAR ─────────────────────────────────────── */
.sidebar {
    width: var(--sidebar-w);
    background: var(--ac-black);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0; left: 0; bottom: 0;
    z-index: 100;
    transition: width .25s ease;
    overflow: hidden;
}
.sidebar.collapsed { width: var(--sidebar-collapsed); }

.sidebar-logo {
    padding: 0 16px;
    height: var(--topbar-h);
    display: flex;
    align-items: center;
    gap: 10px;
    border-bottom: 1px solid rgba(255,255,255,.08);
    flex-shrink: 0;
}
.sidebar-logo-icon {
    width: 32px; height: 32px;
    background: var(--ac-red);
    border-radius: 8px;
    display: flex; align-items: center; justify-content: center;
    flex-shrink: 0;
}
.sidebar-logo-icon span {
    font-family: 'Ovsyanka', sans-serif;
    color: white;
    font-size: 1.1rem;
    font-weight: bold;
}
.sidebar-logo-text {
    font-family: 'Ovsyanka', sans-serif;
    color: white;
    font-size: .85rem;
    letter-spacing: .03em;
    line-height: 1.2;
    white-space: nowrap;
    opacity: 1;
    transition: opacity .2s;
}
.sidebar.collapsed .sidebar-logo-text { opacity: 0; pointer-events: none; }

.sidebar-nav {
    flex: 1;
    overflow-y: auto;
    overflow-x: hidden;
    padding: 12px 0;
    scrollbar-width: thin;
    scrollbar-color: rgba(255,255,255,.1) transparent;
}

.nav-section {
    padding: 16px 16px 4px;
    font-size: .65rem;
    font-weight: 700;
    letter-spacing: .12em;
    color: rgba(255,255,255,.35);
    text-transform: uppercase;
    white-space: nowrap;
    overflow: hidden;
    transition: opacity .2s;
}
.sidebar.collapsed .nav-section { opacity: 0; }

.nav-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 9px 16px;
    color: rgba(255,255,255,.65);
    text-decoration: none;
    font-size: .875rem;
    font-weight: 500;
    white-space: nowrap;
    border-radius: 0;
    transition: background .15s, color .15s;
    position: relative;
}
.nav-item:hover {
    background: rgba(255,255,255,.06);
    color: white;
}
.nav-item.active {
    background: var(--ac-red);
    color: white;
}
.nav-item svg { flex-shrink: 0; }
.nav-item-label {
    transition: opacity .2s;
    overflow: hidden;
}
.sidebar.collapsed .nav-item-label { opacity: 0; }

/* Tooltip en collapsed */
.sidebar.collapsed .nav-item::after {
    content: attr(data-label);
    position: absolute;
    left: calc(var(--sidebar-collapsed) + 8px);
    background: var(--ac-black);
    color: white;
    padding: 5px 10px;
    border-radius: 6px;
    font-size: .8rem;
    white-space: nowrap;
    opacity: 0;
    pointer-events: none;
    transition: opacity .15s;
    z-index: 200;
    box-shadow: var(--shadow-md);
}
.sidebar.collapsed .nav-item:hover::after { opacity: 1; }

.sidebar-footer {
    padding: 12px 0;
    border-top: 1px solid rgba(255,255,255,.08);
}

.sidebar-toggle {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    padding: 10px;
    background: none;
    border: none;
    cursor: pointer;
    color: rgba(255,255,255,.4);
    transition: color .15s;
}
.sidebar-toggle:hover { color: white; }

/* ── MAIN CONTENT ─────────────────────────────────── */
.main-wrapper {
    flex: 1;
    margin-left: var(--sidebar-w);
    transition: margin-left .25s ease;
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}
.sidebar.collapsed ~ .main-wrapper { margin-left: var(--sidebar-collapsed); }

/* ── TOPBAR ─────────────────────────────────────── */
.topbar {
    height: var(--topbar-h);
    background: white;
    border-bottom: 1px solid var(--ac-gray-200);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
}
.topbar-breadcrumb {
    flex: 1;
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: .82rem;
    color: var(--ac-gray-400);
}
.topbar-breadcrumb a { color: var(--ac-gray-600); text-decoration: none; }
.topbar-breadcrumb a:hover { color: var(--ac-red); }
.topbar-breadcrumb .sep { color: var(--ac-gray-200); }
.topbar-breadcrumb .current { color: var(--ac-black); font-weight: 600; }

.topbar-user {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: .82rem;
    color: var(--ac-gray-600);
}
.topbar-avatar {
    width: 32px; height: 32px;
    background: var(--ac-red);
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    color: white;
    font-weight: 700;
    font-size: .8rem;
}

/* ── PAGE CONTENT ─────────────────────────────────── */
.page-content {
    flex: 1;
    padding: 28px 28px 48px;
    max-width: 1400px;
    width: 100%;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
    gap: 16px;
    flex-wrap: wrap;
}
.page-title {
    font-family: 'Ovsyanka', sans-serif;
    font-size: 1.5rem;
    color: var(--ac-black);
    letter-spacing: .02em;
}
.page-subtitle {
    font-size: .82rem;
    color: var(--ac-gray-400);
    margin-top: 2px;
}
.page-actions { display: flex; gap: 8px; align-items: center; flex-wrap: wrap; }

/* ── CARDS ─────────────────────────────────────── */
.card {
    background: white;
    border: 1px solid var(--ac-gray-200);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow);
    margin-bottom: 20px;
}
.card-header {
    padding: 16px 20px;
    border-bottom: 1px solid var(--ac-gray-100);
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 12px;
}
.card-title {
    font-weight: 700;
    font-size: .9rem;
    letter-spacing: .02em;
    text-transform: uppercase;
    color: var(--ac-black);
}
.card-body { padding: 20px; }

/* ── STATS GRID ─────────────────────────────────── */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(200px, 1fr));
    gap: 16px;
    margin-bottom: 24px;
}
.stat-card {
    background: white;
    border: 1px solid var(--ac-gray-200);
    border-radius: var(--radius-lg);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 8px;
}
.stat-card.accent { background: var(--ac-red); border-color: var(--ac-red); color: white; }
.stat-label {
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--ac-gray-400);
}
.stat-card.accent .stat-label { color: rgba(255,255,255,.7); }
.stat-value { font-size: 2rem; font-weight: 700; line-height: 1; }
.stat-icon { color: var(--ac-gray-200); margin-top: auto; }
.stat-card.accent .stat-icon { color: rgba(255,255,255,.3); }

/* ── BUTTONS ─────────────────────────────────────── */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border-radius: var(--radius);
    font-size: .85rem;
    font-weight: 600;
    cursor: pointer;
    text-decoration: none;
    border: none;
    transition: background .15s, color .15s, opacity .15s;
    white-space: nowrap;
    letter-spacing: .01em;
}
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary   { background: var(--ac-red);   color: white; }
.btn-primary:hover { background: var(--ac-red-dark); }

.btn-secondary { background: var(--ac-black); color: white; }
.btn-secondary:hover { background: #374151; }

.btn-success   { background: var(--ac-green); color: white; }
.btn-success:hover { background: #146c43; }

.btn-ghost     { background: transparent; color: var(--ac-gray-600); border: 1px solid var(--ac-gray-200); }
.btn-ghost:hover { background: var(--ac-gray-50); color: var(--ac-black); }

.btn-danger    { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.btn-danger:hover { background: #fecaca; }

.btn-sm  { padding: 5px 11px; font-size: .78rem; }
.btn-lg  { padding: 11px 22px; font-size: .95rem; }
.btn-icon { padding: 7px; }

/* ── TABLES ─────────────────────────────────────── */
.table-wrap { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .85rem; }
thead th {
    padding: 10px 14px;
    text-align: left;
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--ac-gray-400);
    border-bottom: 2px solid var(--ac-gray-100);
    white-space: nowrap;
}
tbody td {
    padding: 11px 14px;
    border-bottom: 1px solid var(--ac-gray-100);
    vertical-align: middle;
}
tbody tr:last-child td { border-bottom: none; }
tbody tr:hover { background: var(--ac-gray-50); }
.td-actions { display: flex; gap: 4px; align-items: center; flex-wrap: wrap; }

/* ── BADGES ─────────────────────────────────────── */
.badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 20px;
    font-size: .72rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-danger  { background: #fee2e2; color: #991b1b; }
.badge-info    { background: #dbeafe; color: #1e40af; }
.badge-default { background: var(--ac-gray-100); color: var(--ac-gray-600); }

/* ── FORMS ─────────────────────────────────────── */
.form-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
}
.form-grid-2 { grid-template-columns: repeat(2, 1fr); }
.form-grid-3 { grid-template-columns: repeat(3, 1fr); }
.col-span-2  { grid-column: span 2; }
.col-span-3  { grid-column: span 3; }
.col-span-full { grid-column: 1 / -1; }

.form-group { display: flex; flex-direction: column; gap: 5px; }
.form-label {
    font-size: .78rem;
    font-weight: 700;
    letter-spacing: .04em;
    text-transform: uppercase;
    color: var(--ac-gray-600);
}
.form-label .req { color: var(--ac-red); margin-left: 2px; }

.form-control {
    width: 100%;
    padding: 9px 12px;
    border: 1px solid var(--ac-gray-200);
    border-radius: var(--radius);
    font-size: .875rem;
    font-family: inherit;
    color: var(--ac-black);
    background: white;
    transition: border-color .15s, box-shadow .15s;
    -webkit-appearance: none;
}
.form-control:focus {
    outline: none;
    border-color: var(--ac-red);
    box-shadow: 0 0 0 3px rgba(229,17,52,.1);
}
.form-control::placeholder { color: var(--ac-gray-400); }
textarea.form-control { resize: vertical; min-height: 90px; }
select.form-control { cursor: pointer; }

.form-hint { font-size: .75rem; color: var(--ac-gray-400); margin-top: 2px; }
.form-error { font-size: .75rem; color: var(--ac-red); margin-top: 2px; }

.form-section {
    padding: 20px;
    border-bottom: 1px solid var(--ac-gray-100);
}
.form-section:last-child { border-bottom: none; }
.form-section-title {
    font-size: .7rem;
    font-weight: 700;
    letter-spacing: .1em;
    text-transform: uppercase;
    color: var(--ac-gray-400);
    margin-bottom: 16px;
}

.form-actions {
    padding: 16px 20px;
    background: var(--ac-gray-50);
    border-top: 1px solid var(--ac-gray-100);
    display: flex;
    gap: 10px;
    align-items: center;
    border-radius: 0 0 var(--radius-lg) var(--radius-lg);
}

/* ── FLASH MESSAGES ─────────────────────────────── */
.flash-container { display: flex; flex-direction: column; gap: 8px; margin-bottom: 20px; }
.flash {
    display: flex;
    align-items: flex-start;
    gap: 10px;
    padding: 12px 16px;
    border-radius: var(--radius);
    font-size: .875rem;
}
.flash-success { background: #d1fae5; color: #065f46; border: 1px solid #a7f3d0; }
.flash-error   { background: #fee2e2; color: #991b1b; border: 1px solid #fecaca; }
.flash-info    { background: #dbeafe; color: #1e40af; border: 1px solid #bfdbfe; }

/* ── FILTROS ─────────────────────────────────────── */
.filter-bar {
    display: flex;
    gap: 10px;
    align-items: center;
    flex-wrap: wrap;
    padding: 14px 20px;
    background: var(--ac-gray-50);
    border-bottom: 1px solid var(--ac-gray-100);
}
.filter-bar .form-control { max-width: 200px; }

/* ── SUBTABLA DINÁMICA ─────────────────────────── */
.subtable { width: 100%; border-collapse: collapse; font-size: .82rem; }
.subtable th {
    padding: 7px 10px;
    background: var(--ac-gray-50);
    font-size: .68rem;
    font-weight: 700;
    letter-spacing: .08em;
    text-transform: uppercase;
    color: var(--ac-gray-400);
    border: 1px solid var(--ac-gray-200);
}
.subtable td {
    padding: 6px 8px;
    border: 1px solid var(--ac-gray-200);
    vertical-align: middle;
}
.subtable .form-control { padding: 5px 8px; font-size: .82rem; }
.subtable-add {
    display: inline-flex;
    align-items: center;
    gap: 5px;
    padding: 6px 12px;
    border: 2px dashed var(--ac-gray-200);
    border-radius: var(--radius);
    font-size: .8rem;
    font-weight: 600;
    color: var(--ac-gray-400);
    cursor: pointer;
    background: none;
    transition: border-color .15s, color .15s;
    margin-top: 8px;
}
.subtable-add:hover { border-color: var(--ac-red); color: var(--ac-red); }

/* ── EMPTY STATE ─────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--ac-gray-400);
}
.empty-state-icon { font-size: 3rem; margin-bottom: 12px; opacity: .4; }
.empty-state-title { font-size: 1rem; font-weight: 700; color: var(--ac-gray-600); margin-bottom: 6px; }
.empty-state-text  { font-size: .85rem; margin-bottom: 20px; }

/* ── TOGGLE SWITCH ─────────────────────────────── */
.toggle-form { display: inline; }
.toggle {
    position: relative;
    width: 38px;
    height: 22px;
    cursor: pointer;
}
.toggle input { opacity: 0; width: 0; height: 0; }
.toggle-slider {
    position: absolute;
    inset: 0;
    background: var(--ac-gray-200);
    border-radius: 22px;
    transition: .2s;
}
.toggle-slider::before {
    content: '';
    position: absolute;
    width: 16px; height: 16px;
    left: 3px; top: 3px;
    background: white;
    border-radius: 50%;
    transition: .2s;
    box-shadow: 0 1px 3px rgba(0,0,0,.2);
}
.toggle input:checked + .toggle-slider { background: var(--ac-green); }
.toggle input:checked + .toggle-slider::before { transform: translateX(16px); }

/* ── PAGINATION ─────────────────────────────────── */
.pagination {
    display: flex;
    gap: 4px;
    align-items: center;
    justify-content: center;
    padding: 16px;
}
.page-link {
    padding: 6px 12px;
    border: 1px solid var(--ac-gray-200);
    border-radius: var(--radius);
    font-size: .82rem;
    color: var(--ac-gray-600);
    text-decoration: none;
    transition: background .15s;
}
.page-link:hover { background: var(--ac-gray-50); }
.page-link.active { background: var(--ac-red); color: white; border-color: var(--ac-red); }

/* ── UTILIDADES ─────────────────────────────────── */
.text-right  { text-align: right; }
.text-center { text-align: center; }
.text-muted  { color: var(--ac-gray-400); }
.text-small  { font-size: .8rem; }
.text-red    { color: var(--ac-red); }
.text-green  { color: var(--ac-green); }
.fw-bold     { font-weight: 700; }
.mb-0 { margin-bottom: 0; }
.mb-1 { margin-bottom: 8px; }
.mb-2 { margin-bottom: 16px; }
.mb-3 { margin-bottom: 24px; }
.mt-1 { margin-top: 8px; }
.mt-2 { margin-top: 16px; }
.d-flex { display: flex; }
.gap-1 { gap: 8px; }
.gap-2 { gap: 16px; }
.align-center { align-items: center; }
.flex-wrap { flex-wrap: wrap; }

/* ── RESPONSIVE ─────────────────────────────────── */
@media (max-width: 768px) {
    .sidebar { width: var(--sidebar-collapsed); }
    .sidebar-logo-text,
    .nav-item-label,
    .nav-section { display: none; }
    .main-wrapper { margin-left: var(--sidebar-collapsed); }
    .page-content { padding: 16px; }
    .stats-grid { grid-template-columns: repeat(2, 1fr); }
    .form-grid-2, .form-grid-3 { grid-template-columns: 1fr; }
    .col-span-2, .col-span-3 { grid-column: span 1; }
}

/* ── LOGIN ─────────────────────────────────────── */
.login-body {
    min-height: 100vh;
    background: var(--ac-black);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
}
.login-card {
    background: white;
    border-radius: var(--radius-lg);
    padding: 40px;
    width: 100%;
    max-width: 400px;
    box-shadow: 0 20px 60px rgba(0,0,0,.3);
}
.login-logo {
    text-align: center;
    margin-bottom: 32px;
}
.login-logo-mark {
    width: 56px; height: 56px;
    background: var(--ac-red);
    border-radius: 14px;
    display: flex; align-items: center; justify-content: center;
    margin: 0 auto 12px;
}
.login-logo-mark span {
    font-family: 'Ovsyanka', sans-serif;
    color: white;
    font-size: 1.5rem;
    font-weight: bold;
}
.login-title {
    font-family: 'Ovsyanka', sans-serif;
    font-size: 1.3rem;
    color: var(--ac-black);
    margin-bottom: 4px;
}
.login-subtitle { font-size: .82rem; color: var(--ac-gray-400); }
