/* ─── iOS design system (iPad-first) ─────────────────────────────────────
   Colors: iOS System Blue, Grays, semantic backgrounds
   Typography: SF Pro-style system font
   Touch: 44px min targets, generous spacing
   Surfaces: grouped lists, rounded corners, subtle separators
────────────────────────────────────────────────────────────────────────── */

:root {
    /* iOS semantic colors */
    --ios-blue: #007AFF;
    --ios-blue-pressed: #0051D5;
    --ios-green: #34C759;
    --ios-red: #FF3B30;
    --ios-orange: #FF9500;
    --ios-yellow: #FFCC00;
    --ios-gray: #8E8E93;
    --ios-gray-2: #AEAEB2;
    --ios-gray-3: #C7C7CC;
    --ios-gray-4: #D1D1D6;
    --ios-gray-5: #E5E5EA;
    --ios-gray-6: #F2F2F7;
    --ios-fill: #F2F2F7;
    --ios-fill-secondary: #E5E5EA;
    --ios-background: #FFFFFF;
    --ios-background-grouped: #F2F2F7;
    --ios-separator: rgba(60, 60, 67, 0.12);
    --ios-label: #000000;
    --ios-label-secondary: rgba(60, 60, 67, 0.6);
    --ios-label-tertiary: rgba(60, 60, 67, 0.3);
}

html {
    font-size: 16px;
    -webkit-text-size-adjust: 100%;
}

html, body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display", "Helvetica Neue", Helvetica, Arial, sans-serif;
    background-color: var(--ios-background-grouped);
    color: var(--ios-label);
    margin: 0;
    padding: 0;
    min-height: 100vh;
    min-height: 100dvh;
}

/* iPad safe area (notch/home indicator) */
body {
    padding-left: env(safe-area-inset-left);
    padding-right: env(safe-area-inset-right);
    padding-bottom: env(safe-area-inset-bottom);
}

/* ─── Layout ────────────────────────────────────────────────────────── */
.layout-root {
    display: flex;
    height: 100vh;
    height: 100dvh;
    min-height: 0;
    overflow: hidden;
}

.layout-sidebar {
    width: 280px;
    min-width: 280px;
    min-height: 0;
    background-color: var(--ios-background);
    border-right: 1px solid var(--ios-separator);
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.layout-sidebar-collapsed {
    width: 48px;
    min-width: 48px;
}

.layout-sidebar-collapsed .sidebar {
    display: none;
}

.sidebar-first-row {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 16px 20px;
    border-bottom: 1px solid var(--ios-separator);
    min-height: 44px;
}

.sidebar-first-row .sidebar-greeting {
    flex: 1;
    min-width: 0;
    padding: 0;
    border: none;
}

.layout-sidebar-collapsed .sidebar-first-row {
    justify-content: center;
    padding: 8px;
}

.layout-sidebar-collapsed .sidebar-first-row .sidebar-greeting {
    display: none;
}

.sidebar-toggle-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    padding: 0;
    border: none;
    border-radius: 8px;
    background: transparent;
    color: var(--ios-label);
    cursor: pointer;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-toggle-btn:hover {
    background-color: var(--ios-gray-5);
}

.sidebar-toggle-btn:active {
    background-color: var(--ios-gray-4);
}

.layout-content {
    flex: 1;
    min-width: 0;
    min-height: 0;
    padding: 20px;
    padding-left: max(20px, env(safe-area-inset-left) + 12px);
    padding-right: max(20px, env(safe-area-inset-right) + 12px);
    padding-bottom: max(20px, env(safe-area-inset-bottom) + 12px);
    overflow: auto;
    -webkit-overflow-scrolling: touch;
    background-color: var(--ios-background-grouped);
}

/* ─── Sidebar (iOS Settings-style list) ──────────────────────────────── */
.sidebar {
    flex: 1;
    min-height: 0;
    background-color: var(--ios-background);
    color: var(--ios-label);
    display: flex;
    flex-direction: column;
    overflow: hidden;
    padding-top: env(safe-area-inset-top);
}

.sidebar-greeting {
    flex-shrink: 0;
    padding: 16px 20px;
    border-bottom: 1px solid var(--ios-separator);
}

.sidebar-greeting-text {
    font-size: 15px;
    color: var(--ios-label);
}

.sidebar-header {
    flex-shrink: 0;
    padding: 16px 20px;
    border-bottom: 1px solid var(--ios-separator);
}

.sidebar-title {
    font-size: 22px;
    font-weight: 700;
    color: #1C1C1E;
}

.sidebar-actions {
    flex-shrink: 0;
    padding: 12px 20px;
    border-bottom: 1px solid var(--ios-separator);
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.sidebar-actions .btn,
.sidebar-actions .form-select,
.sidebar-actions .form-control {
    width: 100%;
}

.sidebar-actions .sidebar-filter-placeholder {
    color: var(--ios-gray);
}

.sidebar-actions .sidebar-filter-placeholder option:not([value=""]) {
    color: var(--ios-label);
}

.sidebar-actions .btn-group {
    display: flex;
}

.sidebar-nav {
    flex: 1;
    min-height: 0;
    padding: 8px 12px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.sidebar-nav .nav-item {
    margin-bottom: 4px;
}

.sidebar-nav .nav-link {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 10px 12px;
    color: #1C1C1E !important;
    text-decoration: none !important;
    border-radius: 10px;
    font-size: 17px;
    transition: background-color 0.15s, color 0.15s;
    -webkit-tap-highlight-color: transparent;
    cursor: pointer;
    background-color: transparent;
}

.sidebar-nav .nav-link:visited {
    color: #1C1C1E !important;
}

.sidebar-nav .nav-link:hover {
    background-color: var(--ios-gray-5) !important;
    color: #1C1C1E !important;
}

.sidebar-nav .nav-link:hover .bi {
    color: #1C1C1E !important;
    opacity: 1;
}

.sidebar-nav .nav-link.active {
    background-color: rgba(0, 122, 255, 0.12) !important;
    color: var(--ios-blue) !important;
    font-weight: 600;
}

.sidebar-nav .nav-link.active .bi {
    color: var(--ios-blue) !important;
    opacity: 1;
}

.sidebar-nav .nav-link:focus-visible {
    outline: 2px solid var(--ios-blue);
    outline-offset: 2px;
}

.sidebar-nav .nav-link .bi {
    font-size: 1.25rem;
    margin-right: 12px;
    color: #1C1C1E;
    opacity: 0.85;
}

.sidebar-nav .nav-sub {
    padding-left: 12px;
    margin-top: 2px;
    margin-bottom: 8px;
    border-left: 2px solid var(--ios-gray-5);
    margin-left: 1rem;
}

.sidebar-nav .nav-sub .nav-link {
    font-size: 15px;
    min-height: 40px;
}

.sidebar-nav .nav-link .bi-chevron-up,
.sidebar-nav .nav-link .bi-chevron-down {
    margin-left: auto;
    margin-right: 4px;
    font-size: 0.875rem;
    color: var(--ios-gray) !important;
}

/* Expandable header (Financeiro) - not a link, keep readable on hover */
.sidebar-nav .nav-link:not([href]) {
    color: #1C1C1E !important;
}

.sidebar-nav .nav-link:not([href]):hover {
    background-color: var(--ios-gray-5) !important;
    color: #1C1C1E !important;
}

.sidebar-nav .nav-link:not([href]) .bi {
    color: #1C1C1E !important;
}

.sidebar-nav .nav-link:not([href]) .bi-chevron-up,
.sidebar-nav .nav-link:not([href]) .bi-chevron-down {
    color: var(--ios-gray) !important;
}

.sidebar-footer {
    flex-shrink: 0;
    padding: 12px 20px;
    border-top: 1px solid var(--ios-separator);
}

.sidebar-logout-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    width: 100%;
    min-height: 44px;
    padding: 10px 16px;
    font-size: 17px;
    font-weight: 500;
    color: var(--ios-blue);
    background: transparent;
    border: none;
    border-radius: 10px;
    cursor: pointer;
    text-decoration: none;
    -webkit-tap-highlight-color: transparent;
}

.sidebar-logout-btn:hover {
    background-color: var(--ios-gray-5);
}

.sidebar-login-link {
    color: var(--ios-blue) !important;
}

/* ─── Page title & actions (iOS large title area) ─────────────────────── */
.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 12px;
    margin-bottom: 20px;
}

.page-title {
    font-size: 34px;
    font-weight: 700;
    color: var(--ios-label);
    margin: 0;
    letter-spacing: 0.4px;
}

/* ─── iOS-style buttons ───────────────────────────────────────────────── */
.btn {
    min-height: 44px;
    padding: 10px 20px;
    font-size: 17px;
    font-weight: 500;
    border-radius: 12px;
    border: none;
    -webkit-tap-highlight-color: transparent;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
}

.btn-primary {
    background-color: var(--ios-blue);
    color: #FFFFFF;
}

.btn-primary:hover,
.btn-primary:focus {
    background-color: var(--ios-blue-pressed);
    color: #FFFFFF;
}

.btn-primary:active {
    opacity: 0.9;
}

.btn-outline-primary {
    background-color: transparent;
    color: var(--ios-blue);
    border: 1px solid var(--ios-blue);
}

.btn-outline-primary:hover,
.btn-outline-primary:focus {
    background-color: rgba(0, 122, 255, 0.1);
    color: var(--ios-blue);
}

.btn-secondary {
    background-color: var(--ios-gray-5);
    color: var(--ios-label);
}

.btn-secondary:hover,
.btn-secondary:focus {
    background-color: var(--ios-gray-4);
    color: var(--ios-label);
}

.btn-outline-secondary {
    background-color: transparent;
    color: var(--ios-gray);
    border: 1px solid var(--ios-gray-4);
}

.btn-outline-secondary:hover {
    background-color: var(--ios-gray-5);
}

.btn-danger {
    background-color: var(--ios-red);
    color: #FFFFFF;
}

.btn-danger:hover,
.btn-danger:focus {
    background-color: #D32F2F;
    color: #FFFFFF;
}

.btn-outline-danger {
    background-color: transparent;
    color: var(--ios-red);
    border: 1px solid var(--ios-red);
}

.btn-outline-danger:hover {
    background-color: rgba(255, 59, 48, 0.1);
}

.btn-sm {
    min-height: 36px;
    padding: 6px 14px;
    font-size: 15px;
    border-radius: 10px;
}

.btn:focus,
.form-control:focus,
.form-select:focus {
    outline: none;
    box-shadow: 0 0 0 2px var(--ios-blue);
}

/* ─── Grouped list (iOS Settings style) ────────────────────────────────── */
.ios-group {
    background-color: var(--ios-background);
    border-radius: 12px;
    overflow: hidden;
    margin-bottom: 24px;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.ios-group-title {
    font-size: 13px;
    font-weight: 400;
    color: var(--ios-label-secondary);
    text-transform: uppercase;
    letter-spacing: 0.5px;
    padding: 16px 16px 8px;
}

.ios-list {
    list-style: none;
    margin: 0;
    padding: 0;
}

.ios-list-item {
    display: flex;
    align-items: center;
    min-height: 44px;
    padding: 12px 16px;
    border-bottom: 1px solid var(--ios-separator);
    background-color: var(--ios-background);
    color: var(--ios-label);
    font-size: 17px;
}

.ios-list-item:last-child {
    border-bottom: none;
}

.ios-list-item:hover {
    background-color: var(--ios-gray-6);
}

.ios-list-item .ios-list-item-label {
    flex: 1;
}

.ios-list-item .ios-list-item-value {
    color: var(--ios-label-secondary);
    font-size: 15px;
}

.ios-list-item .btn-sm {
    margin-left: 8px;
}

/* ─── Table overrides (card-style on iPad) ────────────────────────────── */
.table-responsive {
    border-radius: 12px;
    overflow: hidden;
    background-color: var(--ios-background);
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.06);
}

.table {
    margin-bottom: 0;
    color: var(--ios-label);
}

.table thead th {
    background-color: var(--ios-gray-6) !important;
    color: var(--ios-label-secondary);
    font-size: 13px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.3px;
    border-bottom: 1px solid var(--ios-separator);
    padding: 14px 16px;
}

.table tbody td {
    padding: 14px 16px;
    font-size: 16px;
    vertical-align: middle;
    border-bottom: 1px solid var(--ios-separator);
}

.table tbody tr:last-child td {
    border-bottom: none;
}

.table tbody tr:hover {
    background-color: var(--ios-gray-6);
}

.table-dark thead th {
    background-color: var(--ios-gray-6) !important;
    color: var(--ios-label-secondary);
    border-color: var(--ios-separator);
}

/* ─── Badges (iOS-style pills) ────────────────────────────────────────── */
.badge {
    font-size: 12px;
    font-weight: 600;
    padding: 4px 10px;
    border-radius: 6px;
}

.bg-success, .badge.bg-success { background-color: var(--ios-green) !important; color: #fff !important; }
.bg-danger, .badge.bg-danger { background-color: var(--ios-red) !important; color: #fff !important; }
.bg-warning, .badge.bg-warning { background-color: var(--ios-yellow) !important; color: #000 !important; }
.bg-info, .badge.bg-info { background-color: var(--ios-blue) !important; color: #fff !important; }
.bg-secondary, .badge.bg-secondary { background-color: var(--ios-gray-3) !important; color: #fff !important; }

/* ─── Forms ──────────────────────────────────────────────────────────── */
.form-label {
    font-size: 15px;
    font-weight: 500;
    color: var(--ios-label);
    margin-bottom: 6px;
}

.form-control,
.form-select {
    min-height: 44px;
    padding: 10px 14px;
    font-size: 17px;
    border-radius: 10px;
    border: 1px solid var(--ios-gray-4);
    background-color: var(--ios-background);
    color: var(--ios-label);
}

.form-control:focus,
.form-select:focus {
    border-color: var(--ios-blue);
}

.form-control::placeholder {
    color: var(--ios-label-tertiary);
}

.form-select {
    appearance: none;
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='12' height='12' fill='%238E8E93' viewBox='0 0 16 16'%3E%3Cpath d='M8 11L3 6h10l-5 5z'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 36px;
}

/* ─── Modals (iOS sheet style) ───────────────────────────────────────── */
.modal-backdrop-custom {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 1040;
}

.modal-panel {
    position: fixed;
    top: 50%;
    left: 50%;
    transform: translate(-50%, -50%);
    width: min(560px, 92vw);
    max-height: 88vh;
    background: var(--ios-background);
    border-radius: 14px;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.25);
    z-index: 1050;
    display: flex;
    flex-direction: column;
    overflow: hidden;
}

.modal-panel-sm {
    width: min(400px, 92vw);
}

.modal-panel-lg {
    width: min(720px, 92vw);
}

.modal-panel-xl {
    top: max(20px, env(safe-area-inset-top));
    left: max(20px, env(safe-area-inset-left));
    right: max(20px, env(safe-area-inset-right));
    bottom: max(20px, env(safe-area-inset-bottom));
    width: auto;
    height: auto;
    max-height: none;
    transform: none;
    border-radius: 14px;
}

.modal-panel-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 16px 20px;
    border-bottom: 1px solid var(--ios-separator);
    background: var(--ios-background);
    font-size: 17px;
    font-weight: 600;
}

.modal-panel-header .btn-close {
    width: 44px;
    height: 44px;
    min-width: 44px;
    min-height: 44px;
    padding: 0;
    margin: 0;
    opacity: 0.6;
    border-radius: 10px;
    -webkit-tap-highlight-color: transparent;
}

.modal-panel-header .btn-close:hover {
    opacity: 1;
    background-color: var(--ios-gray-5);
}

.modal-panel-body {
    padding: 20px;
    overflow-y: auto;
    -webkit-overflow-scrolling: touch;
}

.audit-json-block {
    max-height: 280px;
    font-size: 12px;
    white-space: pre-wrap;
    word-break: break-word;
}

/* ─── Empty state & loading ──────────────────────────────────────────── */
.empty-state {
    text-align: center;
    padding: 48px 24px;
    color: var(--ios-label-secondary);
}

.empty-state .bi {
    font-size: 64px;
    color: var(--ios-gray-4);
    margin-bottom: 16px;
}

.empty-state p {
    font-size: 17px;
    margin-bottom: 20px;
}

.loading-state {
    display: flex;
    flex-direction: column;
    align-items: center;
    justify-content: center;
    padding: 48px 24px;
    color: var(--ios-label-secondary);
}

.spinner-border {
    color: var(--ios-blue);
}

/* ─── Alerts ────────────────────────────────────────────────────────── */
.alert {
    border-radius: 12px;
    border: none;
    padding: 14px 18px;
    font-size: 15px;
}

.alert-danger {
    background-color: rgba(255, 59, 48, 0.12);
    color: var(--ios-red);
}

.alert-success {
    background-color: rgba(52, 199, 89, 0.12);
    color: var(--ios-green);
}

/* ─── Login (keep clean, iOS tones) ──────────────────────────────────── */
.login-root {
    min-height: 100vh;
    min-height: 100dvh;
    background: var(--ios-background-grouped);
    display: flex;
    align-items: center;
    justify-content: center;
    padding: env(safe-area-inset-top) env(safe-area-inset-right) env(safe-area-inset-bottom) env(safe-area-inset-left);
}

.login-page {
    width: 100%;
    max-width: 420px;
    padding: 24px;
}

.login-card {
    background: var(--ios-background);
    border-radius: 16px;
    padding: 40px 32px;
    width: 100%;
    text-align: center;
    box-shadow: 0 4px 24px rgba(0, 0, 0, 0.08);
}

.login-title {
    font-size: 28px;
    font-weight: 700;
    color: var(--ios-label);
    margin-bottom: 8px;
}

.login-subtitle {
    color: var(--ios-label-secondary);
    font-size: 16px;
    margin-bottom: 32px;
}

.btn-google {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 10px;
    width: 100%;
    min-height: 50px;
    padding: 12px 20px;
    background: var(--ios-background);
    border: 1px solid var(--ios-gray-4);
    border-radius: 12px;
    font-size: 17px;
    font-weight: 500;
    color: var(--ios-label);
    cursor: pointer;
    transition: background 0.15s, border-color 0.15s;
}

.btn-google:hover {
    background: var(--ios-gray-6);
    border-color: var(--ios-gray-3);
}

/* ─── LoginDisplay (header) ──────────────────────────────────────────── */
.login-display {
    display: flex;
    align-items: center;
    gap: 10px;
    font-size: 15px;
    color: var(--ios-label-secondary);
}

.login-display .btn {
    min-height: 36px;
    padding: 6px 14px;
    font-size: 15px;
}

/* ─── Links ──────────────────────────────────────────────────────────── */
a, .btn-link {
    color: var(--ios-blue);
    text-decoration: none;
}

a:hover, .btn-link:hover {
    color: var(--ios-blue-pressed);
    text-decoration: none;
}

/* ─── Blazor error UI ────────────────────────────────────────────────── */
#blazor-error-ui {
    display: none;
    background: var(--ios-red);
    color: #fff;
    bottom: 0;
    left: 0;
    right: 0;
    padding: 12px 20px;
    position: fixed;
    z-index: 2000;
    font-size: 14px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

#blazor-error-ui.show {
    display: block;
}

#blazor-error-ui .reload {
    color: #fff;
    text-decoration: underline;
}

#blazor-error-ui .dismiss {
    cursor: pointer;
    position: absolute;
    right: 16px;
    top: 50%;
    transform: translateY(-50%);
}

.blazor-error-boundary {
    background: var(--ios-red);
    padding: 16px;
    color: white;
    border-radius: 12px;
}

/* ─── Status badges (movimentações) ────────────────────────────────────── */
.badge.status-liquidado { background-color: var(--ios-green) !important; color: #fff !important; }
.badge.status-vencido { background-color: var(--ios-red) !important; color: #fff !important; }
.badge.status-outro { background-color: var(--ios-gray) !important; color: #fff !important; }

/* ─── Utilities ──────────────────────────────────────────────────────── */
.text-muted { color: var(--ios-label-secondary) !important; }
.cursor-pointer { cursor: pointer; }

/* Sortable table header */
th.sortable {
    cursor: pointer;
    user-select: none;
}

th.sortable:hover {
    background-color: var(--ios-gray-5) !important;
}

h1:focus {
    outline: none;
}

.valid.modified:not([type=checkbox]) {
    outline: 2px solid var(--ios-green);
}

.invalid {
    outline: 2px solid var(--ios-red);
}

.validation-message {
    color: var(--ios-red);
    font-size: 13px;
}

.content {
    padding-top: 0;
}

.dashboard {
    max-width: 1200px;
}

.dashboard-cards .ios-group {
    height: 100%;
}
