*,
*::before,
*::after {
    box-sizing: border-box;
    margin: 0;
    padding: 0;
}

:root {
    --atlas-navy: #071A2B;
    --atlas-blue: #123B5D;
    --atlas-tech: #1C78C0;
    --atlas-green: #2DBE8C;
    --atlas-bg: #F4F7FA;
    --atlas-white: #FFFFFF;
    --atlas-text: #17212B;
    --atlas-text-secondary: #475569;
    --atlas-alert: #F2A93B;
    --atlas-error: #D9534F;
    --atlas-border: #E2E8F0;
    --atlas-sidebar-width: 260px;
    --atlas-header-height: 64px;
    --atlas-radius: 8px;

    /* Mapeamento legado */
    --color-text: var(--atlas-text);
    --color-text-secondary: var(--atlas-text-secondary);
    --color-primary: var(--atlas-tech);
    --color-accent: var(--atlas-tech);
    --color-success: var(--atlas-green);
    --color-warning: var(--atlas-alert);
    --color-danger: var(--atlas-error);
    --color-error: var(--atlas-error);
    --color-surface: var(--atlas-white);
    --color-bg: var(--atlas-bg);
    --color-border: var(--atlas-border);

    --atlas-radius-sm: 4px;
    --atlas-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
    --atlas-shadow-md: 0 4px 12px rgba(0, 0, 0, 0.06);
    --atlas-transition: 0.2s ease;
}

html, body {
    height: 100%;
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    font-size: 15px;
    line-height: 1.5;
    color: var(--atlas-text);
    background: var(--atlas-bg);
    -webkit-font-smoothing: antialiased;
}

input::placeholder,
textarea::placeholder {
    color: var(--atlas-text-secondary);
    opacity: 1;
}

a {
    color: var(--atlas-tech);
    text-decoration: none;
}

a:hover {
    text-decoration: underline;
}

/* ===================== LOGIN PAGE ===================== */

.login-page {
    display: flex;
    min-height: 100vh;
}

.login-institutional {
    flex: 1;
    background: linear-gradient(135deg, var(--atlas-navy) 0%, var(--atlas-blue) 100%);
    color: var(--atlas-white);
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 64px;
    position: relative;
    overflow: hidden;
}

.login-institutional::before {
    content: '';
    position: absolute;
    inset: 0;
    background:
        radial-gradient(ellipse at 20% 80%, rgba(28, 120, 192, 0.15) 0%, transparent 50%),
        radial-gradient(ellipse at 80% 20%, rgba(45, 190, 140, 0.1) 0%, transparent 50%);
    pointer-events: none;
}

.login-institutional-content {
    position: relative;
    z-index: 1;
    max-width: 520px;
}

.login-brand {
    font-size: 2.5rem;
    font-weight: 700;
    letter-spacing: -0.02em;
    line-height: 1;
    margin-bottom: 4px;
}

.login-brand-sub {
    font-size: 1.125rem;
    font-weight: 400;
    color: rgba(255, 255, 255, 0.7);
    margin-bottom: 32px;
    letter-spacing: 0.01em;
}

.login-tagline {
    font-size: 1.25rem;
    font-weight: 500;
    line-height: 1.4;
    margin-bottom: 48px;
    color: rgba(255, 255, 255, 0.9);
}

.login-features {
    display: flex;
    flex-direction: column;
    gap: 16px;
}

.login-feature-item {
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.938rem;
    color: rgba(255, 255, 255, 0.8);
}

.login-feature-icon {
    width: 24px;
    height: 24px;
    flex-shrink: 0;
    border-radius: 6px;
    background: rgba(255, 255, 255, 0.1);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
}

.login-form-area {
    width: 480px;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 64px;
    background: var(--atlas-white);
}

.login-form-container {
    max-width: 360px;
    width: 100%;
}

.login-form-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--atlas-text);
    margin-bottom: 8px;
}

.login-form-subtitle {
    font-size: 0.875rem;
    color: var(--atlas-text-secondary);
    margin-bottom: 32px;
}

.form-group {
    margin-bottom: 20px;
}

.form-label {
    display: block;
    font-size: 0.813rem;
    font-weight: 500;
    color: var(--atlas-text);
    margin-bottom: 6px;
}

.form-input-wrapper {
    position: relative;
}

.form-input {
    width: 100%;
    height: 44px;
    padding: 0 14px;
    font-size: 0.938rem;
    color: var(--atlas-text);
    background: var(--atlas-white);
    border: 1.5px solid var(--atlas-border);
    border-radius: var(--atlas-radius);
    outline: none;
    transition: border-color var(--atlas-transition), box-shadow var(--atlas-transition);
}

.form-input:focus {
    border-color: var(--atlas-tech);
    box-shadow: 0 0 0 3px rgba(28, 120, 192, 0.12);
}

.form-input.error {
    border-color: var(--atlas-error);
}

.form-input.error:focus {
    box-shadow: 0 0 0 3px rgba(217, 83, 79, 0.12);
}

.password-toggle {
    position: absolute;
    right: 10px;
    top: 50%;
    transform: translateY(-50%);
    background: none;
    border: none;
    cursor: pointer;
    color: var(--atlas-text-secondary);
    font-size: 0.75rem;
    padding: 4px 6px;
    border-radius: var(--atlas-radius-sm);
    transition: color var(--atlas-transition);
}

.password-toggle:hover {
    color: var(--atlas-text);
}

.password-toggle:focus-visible {
    outline: 2px solid var(--atlas-tech);
    outline-offset: 2px;
}

.form-options {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 24px;
}

.form-checkbox {
    display: flex;
    align-items: center;
    gap: 8px;
    font-size: 0.813rem;
    color: var(--atlas-text-secondary);
    cursor: pointer;
}

.form-checkbox input[type="checkbox"] {
    width: 16px;
    height: 16px;
    accent-color: var(--atlas-tech);
}

.form-forgot-link {
    font-size: 0.813rem;
    font-weight: 500;
    color: var(--atlas-tech);
}

.form-forgot-link:hover {
    text-decoration: underline;
}

.btn-primary {
    width: 100%;
    height: 44px;
    background: var(--atlas-navy);
    color: var(--atlas-white);
    border: none;
    border-radius: var(--atlas-radius);
    font-size: 0.938rem;
    font-weight: 600;
    cursor: pointer;
    transition: background var(--atlas-transition);
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
}

.btn-primary:hover {
    background: var(--atlas-blue);
}

.btn-primary:focus-visible {
    outline: 2px solid var(--atlas-tech);
    outline-offset: 2px;
}

.btn-primary:disabled {
    opacity: 0.6;
    cursor: not-allowed;
}

.btn-primary.loading {
    pointer-events: none;
}

.spinner {
    display: none;
    width: 18px;
    height: 18px;
    border: 2px solid rgba(255, 255, 255, 0.3);
    border-top-color: var(--atlas-white);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

.btn-primary.loading .spinner {
    display: inline-block;
}

.btn-primary.loading .btn-text {
    opacity: 0.8;
}

@keyframes spin {
    to { transform: rotate(360deg); }
}

.error-message {
    display: none;
    padding: 12px 16px;
    background: #FEF2F2;
    border: 1px solid #FECACA;
    border-radius: var(--atlas-radius);
    color: var(--atlas-error);
    font-size: 0.813rem;
    margin-bottom: 20px;
    align-items: flex-start;
    gap: 8px;
}

.error-message.visible {
    display: flex;
}

.error-message-icon {
    flex-shrink: 0;
    width: 18px;
    height: 18px;
    display: flex;
    align-items: center;
    justify-content: center;
    background: var(--atlas-error);
    color: white;
    border-radius: 50%;
    font-size: 0.688rem;
    font-weight: 700;
    margin-top: 1px;
}

.login-footer {
    margin-top: 32px;
    font-size: 0.75rem;
    color: var(--atlas-text-secondary);
    text-align: center;
}

/* ===================== INTERNAL LAYOUT ===================== */

.app-layout {
    display: flex;
    min-height: 100vh;
}

.app-sidebar {
    width: var(--atlas-sidebar-width);
    background: var(--atlas-navy);
    color: var(--atlas-white);
    display: flex;
    flex-direction: column;
    flex-shrink: 0;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    z-index: 100;
    overflow-y: auto;
}

.sidebar-brand {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 20px 24px;
    border-bottom: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-brand-icon {
    width: 32px;
    height: 32px;
    background: var(--atlas-tech);
    border-radius: 8px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 700;
    flex-shrink: 0;
}

.sidebar-brand-text {
    display: flex;
    flex-direction: column;
}

.sidebar-brand-name {
    font-size: 1rem;
    font-weight: 700;
    letter-spacing: -0.01em;
    line-height: 1.2;
}

.sidebar-brand-sub {
    font-size: 0.688rem;
    color: rgba(255, 255, 255, 0.5);
    letter-spacing: 0.02em;
}

.sidebar-nav {
    padding: 16px 12px;
    flex: 1;
}

.sidebar-section-label {
    font-size: 0.688rem;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: rgba(255, 255, 255, 0.35);
    padding: 8px 12px;
    margin-top: 8px;
}

.sidebar-item {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 10px 12px;
    border-radius: var(--atlas-radius-sm);
    color: rgba(255, 255, 255, 0.65);
    font-size: 0.875rem;
    font-weight: 400;
    cursor: pointer;
    transition: all var(--atlas-transition);
    border: none;
    background: none;
    width: 100%;
    text-align: left;
}

.sidebar-item:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--atlas-white);
}

.sidebar-item.active {
    background: rgba(28, 120, 192, 0.15);
    color: var(--atlas-tech);
    font-weight: 500;
}

.sidebar-item.disabled {
    opacity: 0.35;
    cursor: not-allowed;
    pointer-events: none;
}

.sidebar-item-icon {
    width: 20px;
    height: 20px;
    flex-shrink: 0;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.813rem;
}

.sidebar-footer {
    padding: 16px 12px;
    border-top: 1px solid rgba(255, 255, 255, 0.08);
}

.sidebar-user {
    display: flex;
    align-items: center;
    gap: 10px;
    padding: 8px 12px;
}

.sidebar-user-avatar {
    width: 32px;
    height: 32px;
    border-radius: 50%;
    background: var(--atlas-tech);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 0.75rem;
    font-weight: 600;
    flex-shrink: 0;
    color: white;
}

.sidebar-user-info {
    flex: 1;
    min-width: 0;
}

.sidebar-user-name {
    font-size: 0.813rem;
    font-weight: 500;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
}

.sidebar-user-role {
    font-size: 0.688rem;
    color: rgba(255, 255, 255, 0.4);
}

.app-main {
    flex: 1;
    margin-left: var(--atlas-sidebar-width);
    display: flex;
    flex-direction: column;
    min-height: 100vh;
}

.app-header {
    height: var(--atlas-header-height);
    background: var(--atlas-white);
    border-bottom: 1px solid var(--atlas-border);
    display: flex;
    align-items: center;
    padding: 0 24px;
    gap: 16px;
    flex-shrink: 0;
    position: sticky;
    top: 0;
    z-index: 50;
}

.header-spacer {
    flex: 1;
}

.header-item {
    display: flex;
    align-items: center;
    gap: 6px;
    font-size: 0.813rem;
    color: var(--atlas-text-secondary);
    padding: 6px 10px;
    border-radius: var(--atlas-radius-sm);
    cursor: default;
}

.app-content {
    flex: 1;
    padding: 32px;
}

.app-content-header {
    margin-bottom: 24px;
}

.app-content-title {
    font-size: 1.5rem;
    font-weight: 600;
    color: var(--atlas-text);
}

.app-content-subtitle {
    font-size: 0.875rem;
    color: var(--atlas-text-secondary);
    margin-top: 4px;
}

/* ===================== PLACEHOLDER CARDS ===================== */

.placeholder-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 24px;
}

.placeholder-card {
    background: var(--atlas-white);
    border-radius: var(--atlas-radius);
    border: 1px solid var(--atlas-border);
    padding: 24px;
    transition: box-shadow var(--atlas-transition);
}

.placeholder-card:hover {
    box-shadow: var(--atlas-shadow-md);
}

.placeholder-card-icon {
    width: 40px;
    height: 40px;
    border-radius: 10px;
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1rem;
    margin-bottom: 16px;
}

.placeholder-card-icon.blue { background: rgba(28, 120, 192, 0.1); color: var(--atlas-tech); }
.placeholder-card-icon.green { background: rgba(45, 190, 140, 0.1); color: var(--atlas-green); }
.placeholder-card-icon.amber { background: rgba(242, 169, 59, 0.1); color: var(--atlas-alert); }

.placeholder-card h3 {
    font-size: 0.938rem;
    font-weight: 600;
    margin-bottom: 4px;
}

.placeholder-card p {
    font-size: 0.813rem;
    color: var(--atlas-text-secondary);
}

/* ===================== BUILDING STATE ===================== */

.building-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 80px 24px;
    text-align: center;
}

.building-state-icon {
    width: 64px;
    height: 64px;
    border-radius: 16px;
    background: rgba(28, 120, 192, 0.08);
    display: flex;
    align-items: center;
    justify-content: center;
    font-size: 1.5rem;
    margin-bottom: 24px;
}

.building-state h2 {
    font-size: 1.25rem;
    font-weight: 600;
    color: var(--atlas-text);
    margin-bottom: 8px;
}

.building-state p {
    font-size: 0.875rem;
    color: var(--atlas-text-secondary);
    max-width: 400px;
}

/* ===================== EMPRESA SELECTOR DROPDOWN ===================== */

.atlas-header-company {
  position: relative;
}

.atlas-header-company-menu {
  display: none;
  position: absolute;
  top: 100%;
  left: 0;
  min-width: 320px;
  margin-top: 4px;
  background: var(--atlas-white);
  border: 1px solid var(--atlas-border);
  border-radius: var(--atlas-radius);
  box-shadow: var(--atlas-shadow-md);
  z-index: 200;
  max-height: 320px;
  overflow-y: auto;
}

.atlas-header-company-menu-item {
  display: block;
  padding: 10px 16px;
  font-size: 0.875rem;
  color: var(--atlas-text);
  cursor: pointer;
  transition: background var(--atlas-transition);
  border-bottom: 1px solid var(--atlas-bg);
}

.atlas-header-company-menu-item:last-child {
  border-bottom: none;
}

.atlas-header-company-menu-item:hover {
  background: var(--atlas-bg);
}

.atlas-header-company-menu-loading,
.atlas-header-company-menu-empty {
  padding: 16px;
  font-size: 0.813rem;
  color: var(--atlas-text-secondary);
  text-align: center;
}

/* ===================== RESPONSIVE ===================== */

@media (max-width: 1024px) {
    .login-institutional {
        padding: 48px;
    }
    .login-form-area {
        width: 420px;
        padding: 48px;
    }
}

@media (max-width: 820px) {
    .login-page {
        flex-direction: column;
    }
    .login-institutional {
        padding: 40px 32px;
        min-height: auto;
    }
    .login-institutional-content {
        max-width: 100%;
    }
    .login-form-area {
        width: 100%;
        padding: 40px 32px;
        align-items: center;
    }
}

@media (max-width: 480px) {
    .login-institutional {
        padding: 32px 20px;
    }
    .login-brand {
        font-size: 1.75rem;
    }
    .login-brand-sub {
        font-size: 0.938rem;
        margin-bottom: 20px;
    }
    .login-tagline {
        font-size: 1rem;
        margin-bottom: 32px;
    }
    .login-features {
        display: none;
    }
    .login-form-area {
        padding: 32px 20px;
    }
    .login-form-container {
        max-width: 100%;
    }
    .login-form-title {
        font-size: 1.25rem;
    }
    .app-sidebar {
        width: 100%;
        position: relative;
        height: auto;
    }
    .app-main {
        margin-left: 0;
    }
    .app-content {
        padding: 20px;
    }
}

/* ===================== SKIP LINK ===================== */

.skip-link {
    position: absolute;
    top: -100%;
    left: 8px;
    background: var(--atlas-tech);
    color: white;
    padding: 8px 16px;
    border-radius: var(--atlas-radius-sm);
    z-index: 1000;
    font-weight: 500;
}

.skip-link:focus {
    top: 8px;
}

/* ===================== FOCUS VISIBLE ===================== */

:focus-visible {
    outline: 2px solid var(--atlas-tech);
    outline-offset: 2px;
}

/* ===================== LOGOUT FORM ===================== */

.logout-form {
    display: inline;
}

.logout-button {
    background: none;
    border: none;
    color: rgba(255, 255, 255, 0.65);
    cursor: pointer;
    font-size: 0.813rem;
    padding: 6px 10px;
    border-radius: var(--atlas-radius-sm);
    transition: all var(--atlas-transition);
    display: flex;
    align-items: center;
    gap: 6px;
    width: 100%;
}

.logout-button:hover {
    background: rgba(255, 255, 255, 0.06);
    color: var(--atlas-error);
}

/* ===================== SCREEN READER ONLY ===================== */

.sr-only {
    position: absolute;
    width: 1px;
    height: 1px;
    padding: 0;
    margin: -1px;
    overflow: hidden;
    clip: rect(0, 0, 0, 0);
    white-space: nowrap;
    border: 0;
}
