/* ===== Reset & Variables ===== */
*, *::before, *::after { box-sizing: border-box; margin: 0; padding: 0; }

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --danger: #dc2626;
    --danger-dark: #b91c1c;
    --danger-light: #fee2e2;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #d97706;
    --bg: #f1f5f9;
    --card: #ffffff;
    --text: #0f172a;
    --text-muted: #64748b;
    --border: #e2e8f0;
    --input-bg: #f8fafc;
    --header-bg: #1e293b;
    --radius-sm: 6px;
    --radius: 10px;
    --radius-lg: 16px;
    --shadow-sm: 0 1px 2px rgba(0,0,0,.06);
    --shadow: 0 1px 3px rgba(0,0,0,.1), 0 1px 2px rgba(0,0,0,.06);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,.1), 0 2px 4px -2px rgba(0,0,0,.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,.1), 0 4px 6px -4px rgba(0,0,0,.1);
}

html { font-size: 16px; }

body {
    font-family: system-ui, -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background: var(--bg);
    color: var(--text);
    line-height: 1.5;
    min-height: 100vh;
}

/* ===== Typography ===== */
h1 { font-size: 1.75rem; font-weight: 700; }
h2 { font-size: 1.375rem; font-weight: 600; }
h3 { font-size: 1.125rem; font-weight: 600; }
p  { color: var(--text-muted); }

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 500;
    cursor: pointer;
    transition: background .15s, transform .1s, box-shadow .15s;
    text-decoration: none;
    line-height: 1.4;
    white-space: nowrap;
}
.btn:active { transform: scale(.97); }
.btn:disabled { opacity: .5; cursor: not-allowed; }

.btn-primary   { background: var(--primary); color: #fff; }
.btn-primary:hover:not(:disabled)   { background: var(--primary-dark); }

.btn-danger    { background: var(--danger); color: #fff; }
.btn-danger:hover:not(:disabled)    { background: var(--danger-dark); }

.btn-secondary { background: var(--border); color: var(--text); }
.btn-secondary:hover:not(:disabled) { background: #cbd5e1; }

.btn-ghost  { background: transparent; color: var(--text-muted); }
.btn-ghost:hover:not(:disabled) { background: var(--bg); color: var(--text); }

.btn-sm { padding: 5px 10px; font-size: .8125rem; }
.btn-lg { padding: 11px 24px; font-size: 1rem; }
.btn-icon { padding: 7px; border-radius: var(--radius-sm); }
.btn-full { width: 100%; justify-content: center; }

/* ===== Forms ===== */
.form-group { display: flex; flex-direction: column; gap: 5px; margin-bottom: 16px; }
.form-group:last-of-type { margin-bottom: 0; }

label { font-size: .875rem; font-weight: 500; color: var(--text); }

input, select, textarea {
    padding: 9px 12px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    font-size: .9375rem;
    background: var(--input-bg);
    color: var(--text);
    transition: border-color .15s, box-shadow .15s;
    width: 100%;
    font-family: inherit;
}
input:focus, select:focus, textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37,99,235,.12);
    background: #fff;
}
input::placeholder { color: #94a3b8; }
input.error { border-color: var(--danger); }

.form-hint { font-size: .8rem; color: var(--text-muted); }
.form-error { font-size: .8rem; color: var(--danger); }
.form-row { display: grid; grid-template-columns: 1fr 1fr; gap: 12px; }

/* ===== Cards ===== */
.card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 24px;
}
.card-sm { padding: 16px; }

/* ===== Header ===== */
.app-header {
    background: var(--header-bg);
    color: #fff;
    height: 60px;
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    position: sticky;
    top: 0;
    z-index: 50;
    box-shadow: var(--shadow-md);
}
.app-header .brand { font-size: 1.25rem; font-weight: 700; color: #fff; flex: 1; }
.app-header .brand span { color: #93c5fd; }
.header-actions { display: flex; align-items: center; gap: 8px; }
.header-user { font-size: .875rem; color: #94a3b8; }

/* ===== Page Layout ===== */
.page { max-width: 1100px; margin: 0 auto; padding: 32px 20px; }
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 28px;
    flex-wrap: wrap;
    gap: 12px;
}
.page-title { font-size: 1.5rem; font-weight: 700; }
.page-subtitle { color: var(--text-muted); font-size: .9rem; margin-top: 2px; }

/* ===== Auth Page ===== */
.auth-page {
    min-height: 100vh;
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #1e3a5f 0%, #1e293b 60%, #0f172a 100%);
    padding: 20px;
}
.auth-box {
    background: var(--card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 420px;
    overflow: hidden;
}
.auth-header {
    background: linear-gradient(135deg, var(--primary) 0%, #1e40af 100%);
    padding: 32px 32px 24px;
    text-align: center;
    color: #fff;
}
.auth-header .logo { font-size: 2.5rem; margin-bottom: 4px; }
.auth-header h1 { font-size: 1.75rem; color: #fff; margin-bottom: 4px; }
.auth-header p { color: rgba(255,255,255,.75); font-size: .9rem; margin: 0; }

.auth-tabs {
    display: flex;
    border-bottom: 1.5px solid var(--border);
}
.auth-tab {
    flex: 1;
    padding: 13px;
    background: none;
    border: none;
    font-size: .9375rem;
    font-weight: 500;
    color: var(--text-muted);
    cursor: pointer;
    transition: color .15s, border-bottom .15s;
    border-bottom: 2.5px solid transparent;
    margin-bottom: -1.5px;
}
.auth-tab.active { color: var(--primary); border-bottom-color: var(--primary); }
.auth-tab:hover:not(.active) { color: var(--text); background: var(--bg); }

.auth-form { padding: 28px 32px 32px; display: none; }
.auth-form.active { display: block; }

.auth-footer { text-align: center; margin-top: 16px; font-size: .875rem; color: var(--text-muted); }

/* ===== Project Grid ===== */
.projects-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(300px, 1fr));
    gap: 20px;
}
.project-card {
    background: var(--card);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    padding: 20px;
    display: flex;
    flex-direction: column;
    gap: 12px;
    transition: box-shadow .2s, transform .2s;
    border: 1.5px solid transparent;
}
.project-card:hover {
    box-shadow: var(--shadow-md);
    transform: translateY(-2px);
    border-color: var(--primary-light);
}
.project-card-header { display: flex; align-items: flex-start; justify-content: space-between; gap: 8px; }
.project-name { font-size: 1.0625rem; font-weight: 600; line-height: 1.3; }
.project-badge {
    background: var(--primary-light);
    color: var(--primary);
    font-size: .75rem;
    font-weight: 600;
    padding: 3px 8px;
    border-radius: 20px;
    white-space: nowrap;
}
.project-meta { display: flex; flex-direction: column; gap: 5px; }
.meta-row { display: flex; align-items: center; gap: 6px; font-size: .8375rem; color: var(--text-muted); }
.meta-row svg { flex-shrink: 0; }
.project-actions { display: flex; gap: 8px; margin-top: 4px; }
.project-actions .btn { flex: 1; justify-content: center; }

/* ===== Project Detail ===== */
.detail-header { display: flex; align-items: center; gap: 12px; margin-bottom: 24px; }
.detail-info-card { margin-bottom: 32px; }
.detail-info-grid { display: grid; grid-template-columns: repeat(auto-fit, minmax(180px, 1fr)); gap: 16px; margin-top: 16px; }
.info-item label { font-size: .75rem; text-transform: uppercase; letter-spacing: .05em; color: var(--text-muted); font-weight: 600; }
.info-item p  { font-size: 1rem; color: var(--text); font-weight: 500; margin: 2px 0 0; }

/* ===== Table ===== */
.table-wrapper { overflow-x: auto; }
table { width: 100%; border-collapse: collapse; font-size: .9rem; }
thead th {
    background: var(--bg);
    padding: 10px 14px;
    text-align: left;
    font-size: .75rem;
    text-transform: uppercase;
    letter-spacing: .05em;
    color: var(--text-muted);
    font-weight: 600;
    border-bottom: 1.5px solid var(--border);
}
tbody tr { border-bottom: 1px solid var(--border); transition: background .1s; }
tbody tr:last-child { border-bottom: none; }
tbody tr:hover { background: #f8fafc; }
tbody td { padding: 12px 14px; }
.td-actions { display: flex; gap: 6px; justify-content: flex-end; align-items: center; }

.btn-icon-action {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 32px;
    height: 32px;
    border: none;
    border-radius: var(--radius-sm);
    cursor: pointer;
    transition: background .15s, color .15s, transform .1s;
    flex-shrink: 0;
}
.btn-icon-action:active { transform: scale(.92); }

.btn-edit   { background: #e0f0ff; color: #2563eb; }
.btn-edit:hover   { background: #bfdbfe; color: #1d4ed8; }

.btn-delete { background: #fee2e2; color: var(--danger); }
.btn-delete:hover { background: #fecaca; color: var(--danger-dark); }

.btn-report { background: #dcfce7; color: #16a34a; }
.btn-report:hover { background: #bbf7d0; color: #15803d; }

.btn-view  { background: #f1f5ff; color: #6366f1; }
.btn-view:hover  { background: #e0e7ff; color: #4f46e5; }

.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}
.empty-state .empty-icon { font-size: 3rem; margin-bottom: 12px; }
.empty-state h3 { color: var(--text); margin-bottom: 4px; }

/* ===== Modal ===== */
.modal-overlay {
    position: fixed;
    inset: 0;
    background: rgba(15,23,42,.55);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 200;
    padding: 16px;
    opacity: 0;
    pointer-events: none;
    transition: opacity .2s;
}
.modal-overlay.open {
    opacity: 1;
    pointer-events: all;
}
.modal {
    background: var(--card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 480px;
    max-height: calc(100vh - 48px);
    display: flex;
    flex-direction: column;
    transform: scale(.95) translateY(8px);
    transition: transform .2s;
    overflow: hidden;
}
.modal-overlay.open .modal { transform: scale(1) translateY(0); }
.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1.5px solid var(--border);
    flex-shrink: 0;
}
.modal-header h2 { font-size: 1.125rem; }
.modal-body {
    padding: 24px;
    overflow-y: auto;
    flex: 1;
}
.modal-footer {
    display: flex;
    justify-content: flex-end;
    gap: 10px;
    padding: 16px 24px;
    border-top: 1.5px solid var(--border);
    background: var(--bg);
    flex-shrink: 0;
}

/* ===== Toast ===== */
.toast-container { position: fixed; bottom: 24px; right: 24px; z-index: 999; display: flex; flex-direction: column; gap: 8px; }
.toast {
    padding: 12px 20px;
    border-radius: var(--radius-sm);
    color: #fff;
    font-size: .875rem;
    font-weight: 500;
    box-shadow: var(--shadow-md);
    transform: translateX(120%);
    transition: transform .3s cubic-bezier(.34,1.56,.64,1);
    min-width: 240px;
    max-width: 360px;
}
.toast.show { transform: translateX(0); }
.toast.success { background: var(--success); }
.toast.error   { background: var(--danger); }
.toast.info    { background: var(--primary); }

/* ===== Alert ===== */
.alert {
    padding: 12px 16px;
    border-radius: var(--radius-sm);
    font-size: .875rem;
    font-weight: 500;
    margin-bottom: 16px;
    display: none;
}
.alert.show { display: block; }
.alert-error { background: var(--danger-light); color: var(--danger-dark); border: 1px solid #fca5a5; }
.alert-success { background: var(--success-light); color: #15803d; border: 1px solid #86efac; }

/* ===== Loading ===== */
.spinner {
    display: inline-block;
    width: 18px; height: 18px;
    border: 2.5px solid rgba(255,255,255,.4);
    border-top-color: #fff;
    border-radius: 50%;
    animation: spin .7s linear infinite;
}
.spinner-dark {
    border-color: rgba(37,99,235,.2);
    border-top-color: var(--primary);
}
@keyframes spin { to { transform: rotate(360deg); } }

.page-loader {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 200px;
    gap: 12px;
    color: var(--text-muted);
    font-size: .9375rem;
}

/* ===== Misc ===== */
.divider { border: none; border-top: 1.5px solid var(--border); margin: 20px 0; }
.text-muted { color: var(--text-muted); }
.text-danger { color: var(--danger); }
.text-success { color: var(--success); }
.fw-600 { font-weight: 600; }
.mb-0 { margin-bottom: 0 !important; }
.section-header { display: flex; align-items: center; justify-content: space-between; margin-bottom: 16px; }
.section-title { font-size: 1.125rem; font-weight: 600; }

/* ===== Chip ===== */
.chip {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: .75rem;
    font-weight: 600;
}
.chip-blue { background: var(--primary-light); color: var(--primary-dark); }
.chip-gray { background: var(--border); color: var(--text-muted); }

/* ===== Report Page ===== */
.report-page-body {
    min-height: 100vh;
    background: var(--bg);
    display: flex;
    flex-direction: column;
}
.report-hero {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 48px 20px;
}
.report-card {
    background: var(--card);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-lg);
    padding: 48px 40px;
    width: 100%;
    max-width: 500px;
    text-align: center;
}
.report-card-icon { font-size: 2.75rem; margin-bottom: 10px; }
.report-card-title { font-size: 1.75rem; font-weight: 700; margin-bottom: 8px; }
.report-card-subtitle { color: var(--text-muted); font-size: .9375rem; margin-bottom: 28px; }
.report-preview {
    background: var(--bg);
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    padding: 12px 16px;
    margin-bottom: 16px;
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    letter-spacing: .02em;
}

/* ===== Compact login in header ===== */
.header-login-area {
    display: flex;
    align-items: center;
    gap: 8px;
    flex-wrap: wrap;
}
.header-input {
    padding: 6px 10px;
    font-size: .8125rem;
    width: 150px;
    background: rgba(255,255,255,.12);
    border: 1.5px solid rgba(255,255,255,.2);
    border-radius: var(--radius-sm);
    color: #fff;
    height: 32px;
    font-family: inherit;
    transition: border-color .15s, background .15s;
}
.header-input::placeholder { color: rgba(255,255,255,.4); }
.header-input:focus {
    outline: none;
    border-color: rgba(255,255,255,.55);
    background: rgba(255,255,255,.18);
    box-shadow: 0 0 0 3px rgba(255,255,255,.08);
}
.header-login-error { font-size: .8rem; color: #fca5a5; white-space: nowrap; }
.header-user-area { display: flex; align-items: center; gap: 10px; }

/* ===== Modal grande ===== */
.modal-lg { max-width: 760px; }

/* ===== Secciones de formulario ===== */
.form-section { margin-top: 24px; }
.form-section:first-child { margin-top: 0; }
.form-section-title {
    font-size: .6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--primary);
    padding-bottom: 7px;
    border-bottom: 1.5px solid var(--primary-light);
    margin-bottom: 14px;
}
.form-subsection { margin-top: 14px; }
.form-subsection-title {
    font-size: .75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin-bottom: 10px;
}
.form-row-3 { display: grid; grid-template-columns: 1fr 1fr 1fr; gap: 12px; }
.unit { font-size: .75rem; color: var(--text-muted); font-weight: 400; }

/* ===== Responsive ===== */
@media (max-width: 640px) {
    .form-row { grid-template-columns: 1fr; }
    .form-row-3 { grid-template-columns: 1fr; }
    .projects-grid { grid-template-columns: 1fr; }
    .page { padding: 20px 14px; }
    .modal { max-width: 100%; }
    table { font-size: .8125rem; }
    thead th, tbody td { padding: 9px 10px; }
    .app-header { padding: 0 14px; }
    .header-user { display: none; }
}
@media (max-width: 900px) {
    .modal-lg { max-width: 96vw; }
    .form-row-3 { grid-template-columns: 1fr 1fr; }
}

/* ===== Agitador detail page ===== */
.det-layout {
    display: grid;
    grid-template-columns: 1fr 400px;
    gap: 24px;
    align-items: start;
}
@media (max-width: 960px) {
    .det-layout { grid-template-columns: 1fr; }
    .det-sens-wrap { position: static !important; }
}

.det-data { display: flex; flex-direction: column; gap: 20px; }

.det-section-title {
    font-size: .6875rem;
    font-weight: 700;
    text-transform: uppercase;
    letter-spacing: .09em;
    color: var(--primary);
    padding-bottom: 7px;
    border-bottom: 1.5px solid var(--primary-light);
    margin-bottom: 14px;
}
.det-subsection-title {
    font-size: .75rem;
    font-weight: 600;
    color: var(--text-muted);
    margin: 14px 0 8px;
}
.det-subsection-title:first-of-type { margin-top: 0; }

.det-attr-table { width: 100%; border-collapse: collapse; }
.det-attr-table td {
    padding: 7px 4px;
    vertical-align: middle;
    border-bottom: 1px solid #f1f5f9;
    font-size: .875rem;
}
.det-attr-table tr:last-child td { border-bottom: none; }
.dat-label { color: var(--text-muted); width: 52%; }
.dat-value { font-weight: 500; color: var(--text); }
.dat-unit  { color: var(--text-muted); font-size: .75rem; padding-right: 8px; text-align: right; }
.dat-action { width: 32px; text-align: right; }

.btn-sens {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 26px;
    height: 26px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: transparent;
    cursor: pointer;
    color: var(--text-muted);
    transition: background .15s, color .15s, border-color .15s;
    flex-shrink: 0;
}
.btn-sens:hover, .btn-sens.active {
    background: #eff6ff;
    color: #3b82f6;
    border-color: #93c5fd;
}
.btn-sens-placeholder { display: inline-block; width: 26px; height: 26px; }

/* Sensitivity panel */
.det-sens-wrap {
    position: sticky;
    top: 24px;
    display: none;
}
.det-sens-wrap.open { display: block; }

.det-sens-panel { padding: 0; overflow: hidden; }
.det-sens-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--border);
    background: #f8fafc;
}
.det-sens-eyebrow {
    font-size: .7rem;
    text-transform: uppercase;
    letter-spacing: .07em;
    color: var(--text-muted);
    font-weight: 600;
    margin-bottom: 2px;
}
.det-sens-title { font-size: 1rem; font-weight: 700; color: var(--text); }
.det-sens-body { padding: 18px 20px; }
.det-sens-current { font-size: .8125rem; color: var(--text-muted); margin-bottom: 14px; }

.det-sens-chart-wrap {
    position: relative;
    height: 280px;
    margin-top: 16px;
}
.det-sens-nodata {
    display: flex;
    align-items: center;
    justify-content: center;
    height: 160px;
    color: var(--text-muted);
    font-size: .875rem;
    border: 1.5px dashed var(--border);
    border-radius: var(--radius-sm);
    margin-top: 16px;
    text-align: center;
    padding: 16px;
}

/* ===== Edit inputs inside detail attribute table ===== */
.edit-input {
    padding: 5px 8px;
    border: 1.5px solid var(--border);
    border-radius: var(--radius-sm);
    background: var(--input-bg);
    color: var(--text);
    font-size: .875rem;
    font-family: inherit;
    transition: border-color .15s, box-shadow .15s;
    width: 100%;
    max-width: 150px;
}
.edit-input:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 2px rgba(37,99,235,.1);
    background: #fff;
}
select.edit-input { max-width: 160px; }
