/* ================================================================
   TrackMax Cupertino — Design System
   Inspirado em iOS/macOS nativo, com identidade visual TrackMax.
   Cores da marca: Navy #1a2d5a + Red #e31937 (do logo TrackMax).
   Carregado por includes/cupertino_head.php.
   Nao depende de Bootstrap — usar apenas em paginas totalmente migradas.

   Tokens de cor:
     --tm-navy:       #1a2d5a   Primary (substitui ios-blue)
     --tm-navy-dark:  #0a1628   Hover/pressed
     --tm-navy-light: #2d4a87   Accent claro
     --tm-red:        #e31937   Danger/Alert/Brand accent
     iOS-semantic:    #34C759 (success), #FF9500 (warning)
   ================================================================ */

:root {
    --tm-navy:        #1a2d5a;
    --tm-navy-dark:   #0a1628;
    --tm-navy-light:  #2d4a87;
    --tm-red:         #e31937;
    --tm-red-dark:    #b3122a;
    --ios-success:    #34C759;
    --ios-warning:    #FF9500;
    --ios-text:       #1c1c1e;
    --ios-bg:         #F2F2F7;
    --ios-gray-1:     #8E8E93;
    --ios-separator:  #C6C6C8;
}

/* ----------------------------------------------------------------
   1. Base
   ---------------------------------------------------------------- */
html {
    -webkit-text-size-adjust: 100%;
}

body {
    font-family: -apple-system, BlinkMacSystemFont, "SF Pro Display",
                 "SF Pro Text", "Helvetica Neue", Helvetica, Arial, sans-serif;
    background: #F2F2F7;
    color: #1c1c1e;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
    -webkit-tap-highlight-color: transparent;
    margin: 0;
    font-size: 15px;
    line-height: 1.5;
}

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

a { color: #1a2d5a; text-decoration: none; }
a:hover { text-decoration: underline; color: #0a1628; }

/* ----------------------------------------------------------------
   2. Tipografia
   ---------------------------------------------------------------- */
.ios-h1 {
    font-size: 34px;
    font-weight: 700;
    letter-spacing: -0.02em;
    color: #1c1c1e;
    margin: 0;
}
.ios-h2 {
    font-size: 22px;
    font-weight: 700;
    letter-spacing: -0.01em;
    color: #1c1c1e;
    margin: 0;
}
.ios-subtitle {
    font-size: 15px;
    color: #8E8E93;
    margin: 0;
}
.ios-section-header {
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.06em;
    color: #8E8E93;
    margin: 0;
}
.ios-label { font-size: 13px; font-weight: 500; color: #8E8E93; }
.ios-kpi   { font-size: 34px; font-weight: 700; color: #1a2d5a; }

/* ----------------------------------------------------------------
   3. Inputs
   ---------------------------------------------------------------- */
.ios-input,
.ios-textarea,
.ios-select {
    display: block;
    width: 100%;
    border-radius: 10px;
    padding: 11px 16px;
    font-size: 16px;
    font-family: inherit;
    color: #1c1c1e;
    background: rgba(118, 118, 128, 0.12);
    border: none;
    outline: none;
    transition: background 0.2s, box-shadow 0.2s;
    -webkit-appearance: none;
    appearance: none;
}
.ios-input::placeholder,
.ios-textarea::placeholder { color: #8E8E93; }

.ios-input:focus,
.ios-textarea:focus,
.ios-select:focus {
    background: rgba(118, 118, 128, 0.18);
    box-shadow: 0 0 0 3px rgba(26, 45, 90, 0.25);
}

.ios-input:disabled,
.ios-textarea:disabled,
.ios-select:disabled {
    opacity: 0.5;
    cursor: not-allowed;
}

.ios-textarea { min-height: 96px; resize: vertical; line-height: 1.4; }

.ios-select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='16' height='16' viewBox='0 0 24 24' fill='none' stroke='%238E8E93' stroke-width='2.2' stroke-linecap='round' stroke-linejoin='round'%3E%3Cpolyline points='6 9 12 15 18 9'%3E%3C/polyline%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right 14px center;
    padding-right: 40px;
}

.ios-input-label {
    display: block;
    font-size: 13px;
    font-weight: 500;
    color: #8E8E93;
    margin-bottom: 6px;
    padding-left: 4px;
}

/* ----------------------------------------------------------------
   4. Botoes
   ---------------------------------------------------------------- */
.ios-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    border-radius: 12px;
    padding: 12px 20px;
    font-size: 17px;
    font-weight: 600;
    font-family: inherit;
    border: none;
    cursor: pointer;
    transition: transform 0.15s ease-out, opacity 0.15s ease-out, background 0.15s;
    text-decoration: none;
    white-space: nowrap;
    user-select: none;
}
.ios-btn:active { transform: scale(0.97); opacity: 0.85; }
.ios-btn:disabled { opacity: 0.4; cursor: not-allowed; transform: none; }

/* Primary: TrackMax Navy (cor principal da marca) */
.ios-btn-primary    { background: #1a2d5a; color: #fff; }
.ios-btn-primary:hover:not(:disabled)   { background: #0a1628; }

.ios-btn-secondary  { background: rgba(26, 45, 90, 0.1); color: #1a2d5a; }
.ios-btn-secondary:hover:not(:disabled) { background: rgba(26, 45, 90, 0.18); }

/* Danger: TrackMax Red (cor de acento da marca) */
.ios-btn-danger     { background: rgba(227, 25, 55, 0.1); color: #e31937; }
.ios-btn-danger:hover:not(:disabled)    { background: rgba(227, 25, 55, 0.18); }

/* Brand: vermelho TrackMax solido (para CTAs destacadas) */
.ios-btn-brand      { background: #e31937; color: #fff; }
.ios-btn-brand:hover:not(:disabled)     { background: #b3122a; }

.ios-btn-success    { background: rgba(52, 199, 89, 0.12); color: #248a3d; }
.ios-btn-success:hover:not(:disabled)   { background: rgba(52, 199, 89, 0.2); }

.ios-btn-ghost      { background: transparent; color: #1a2d5a; }
.ios-btn-ghost:hover:not(:disabled)     { background: rgba(26, 45, 90, 0.08); }

.ios-btn-sm { padding: 8px 14px; font-size: 15px; border-radius: 10px; }
.ios-btn-lg { padding: 14px 24px; font-size: 18px; border-radius: 14px; }
.ios-btn-block { display: flex; width: 100%; }

/* ----------------------------------------------------------------
   5. Cards
   ---------------------------------------------------------------- */
.ios-card {
    background: #fff;
    border-radius: 14px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 2px rgba(0, 0, 0, 0.04);
}
.ios-card-lg  { border-radius: 16px; }
.ios-card-xl  { border-radius: 20px; }

.ios-card-inset { background: #fff; border-radius: 12px; margin: 0 16px; }

.ios-card-header {
    padding: 16px 20px 12px;
    border-bottom: 0.5px solid #C6C6C8;
}
.ios-card-body   { padding: 16px 20px; }
.ios-card-footer {
    padding: 12px 20px;
    border-top: 0.5px solid #C6C6C8;
    background: rgba(242, 242, 247, 0.5);
}

/* ----------------------------------------------------------------
   6. Segment control (abas iOS)
   ---------------------------------------------------------------- */
.ios-segment {
    background: rgba(118, 118, 128, 0.12);
    border-radius: 9px;
    padding: 2px;
    display: inline-flex;
    gap: 0;
}
.ios-segment-item {
    padding: 6px 16px;
    font-size: 13px;
    font-weight: 500;
    color: #1c1c1e;
    border-radius: 7px;
    cursor: pointer;
    transition: background 0.2s, box-shadow 0.2s;
    border: none;
    background: transparent;
    font-family: inherit;
}
.ios-segment-item.active {
    background: #fff;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08), 0 1px 1px rgba(0, 0, 0, 0.04);
    font-weight: 600;
}

/* ----------------------------------------------------------------
   7. List rows (estilo iOS Settings)
   ---------------------------------------------------------------- */
.ios-list {
    background: #fff;
    border-radius: 12px;
    overflow: hidden;
    box-shadow: 0 1px 3px rgba(0, 0, 0, 0.08);
}
.ios-list-row {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 16px;
    background: #fff;
    color: #1c1c1e;
    text-decoration: none;
    font-size: 15px;
    transition: background 0.15s;
}
.ios-list-row:hover  { background: #f9f9fb; text-decoration: none; }
.ios-list-row:active { background: #e5e5ea; }
.ios-list-row + .ios-list-row {
    border-top: 0.5px solid #C6C6C8;
    margin-left: 16px;
}
.ios-list-row-icon {
    width: 28px; height: 28px;
    border-radius: 6px;
    display: flex; align-items: center; justify-content: center;
    color: #fff;
    flex-shrink: 0;
}
.ios-list-row-title { flex: 1; font-weight: 500; }
.ios-list-row-value { color: #8E8E93; font-size: 14px; }
.ios-list-row-chev  { color: #C7C7CC; flex-shrink: 0; }

/* ----------------------------------------------------------------
   8. Badges (pills)
   ---------------------------------------------------------------- */
.ios-badge {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 980px;
    font-size: 12px;
    font-weight: 600;
    letter-spacing: 0.02em;
    background: rgba(142, 142, 147, 0.18);
    color: #1c1c1e;
    white-space: nowrap;
}
.ios-badge-blue    { background: rgba(26, 45, 90, 0.12);   color: #1a2d5a; }
.ios-badge-navy    { background: rgba(26, 45, 90, 0.12);   color: #1a2d5a; }
.ios-badge-green   { background: rgba(52, 199, 89, 0.15);  color: #248a3d; }
.ios-badge-red     { background: rgba(227, 25, 55, 0.12);  color: #e31937; }
.ios-badge-brand   { background: rgba(227, 25, 55, 0.12);  color: #e31937; }
.ios-badge-orange  { background: rgba(255, 149, 0, 0.15);  color: #c76800; }
.ios-badge-yellow  { background: rgba(255, 204, 0, 0.2);   color: #8a6d00; }
.ios-badge-purple  { background: rgba(175, 82, 222, 0.15); color: #AF52DE; }
.ios-badge-pink    { background: rgba(255, 45, 85, 0.15);  color: #FF2D55; }
.ios-badge-teal    { background: rgba(90, 200, 250, 0.18); color: #0a7fa8; }
.ios-badge-gray    { background: rgba(142, 142, 147, 0.18); color: #6a6a6e; }

/* ----------------------------------------------------------------
   9. Blur (navbar/sidebar translucidos)
   ---------------------------------------------------------------- */
.ios-blur {
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
}

/* ----------------------------------------------------------------
   10. Toggle switch iOS
   ---------------------------------------------------------------- */
.ios-toggle {
    position: relative;
    display: inline-block;
    width: 51px;
    height: 31px;
    flex-shrink: 0;
}
.ios-toggle input {
    opacity: 0;
    width: 0;
    height: 0;
}
.ios-toggle-slider {
    position: absolute;
    cursor: pointer;
    inset: 0;
    background: #E5E5EA;
    border-radius: 31px;
    transition: background 0.25s;
}
.ios-toggle-slider::before {
    content: "";
    position: absolute;
    left: 2px;
    top: 2px;
    width: 27px;
    height: 27px;
    background: #fff;
    border-radius: 50%;
    box-shadow: 0 3px 8px rgba(0, 0, 0, 0.15), 0 1px 1px rgba(0, 0, 0, 0.04);
    transition: transform 0.25s;
}
.ios-toggle input:checked + .ios-toggle-slider { background: #34C759; }
.ios-toggle input:checked + .ios-toggle-slider::before { transform: translateX(20px); }
.ios-toggle input:focus-visible + .ios-toggle-slider { box-shadow: 0 0 0 3px rgba(26, 45, 90, 0.35); }

/* ----------------------------------------------------------------
   11. Toasts (notificacoes flutuantes)
   ---------------------------------------------------------------- */
.ios-toast-container {
    position: fixed;
    top: calc(20px + env(safe-area-inset-top, 0px));
    right: 20px;
    left: 20px;
    z-index: 9999;
    display: flex;
    flex-direction: column;
    align-items: flex-end;
    gap: 8px;
    pointer-events: none;
}
.ios-toast {
    padding: 12px 20px;
    border-radius: 12px;
    font-size: 15px;
    font-weight: 500;
    box-shadow: 0 8px 30px rgba(0, 0, 0, 0.15);
    animation: iosSlideIn 0.3s ease-out;
    pointer-events: auto;
    max-width: 400px;
    color: #fff;
}
.ios-toast-success { background: #34C759; }
.ios-toast-error   { background: #e31937; }
.ios-toast-info    { background: #1a2d5a; }
.ios-toast-warning { background: #FF9500; }
.ios-toast.closing { animation: iosSlideOut 0.25s ease-in forwards; }

@keyframes iosSlideIn {
    from { transform: translateX(110%); opacity: 0; }
    to   { transform: translateX(0); opacity: 1; }
}
@keyframes iosSlideOut {
    from { transform: translateX(0); opacity: 1; }
    to   { transform: translateX(110%); opacity: 0; }
}

/* ----------------------------------------------------------------
   12. Modal (Alpine.js-friendly)
   ---------------------------------------------------------------- */
.ios-modal-backdrop {
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.4);
    backdrop-filter: blur(4px);
    -webkit-backdrop-filter: blur(4px);
    z-index: 10000;
    display: flex;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: iosFadeIn 0.2s ease-out;
}
.ios-modal {
    background: #fff;
    border-radius: 20px;
    max-width: 500px;
    width: 100%;
    max-height: calc(100vh - 40px);
    overflow: hidden;
    display: flex;
    flex-direction: column;
    box-shadow: 0 20px 60px rgba(0, 0, 0, 0.3);
    animation: iosModalUp 0.3s cubic-bezier(0.2, 0.9, 0.3, 1);
}
.ios-modal-header {
    padding: 20px 24px 12px;
    border-bottom: 0.5px solid #C6C6C8;
    display: flex;
    align-items: center;
    justify-content: space-between;
}
.ios-modal-title { font-size: 17px; font-weight: 600; color: #1c1c1e; }
.ios-modal-close {
    background: rgba(142, 142, 147, 0.2);
    border: none;
    width: 30px; height: 30px;
    border-radius: 50%;
    display: flex; align-items: center; justify-content: center;
    cursor: pointer;
    color: #8E8E93;
    transition: background 0.15s;
}
.ios-modal-close:hover { background: rgba(142, 142, 147, 0.3); color: #1c1c1e; }
.ios-modal-body   { padding: 20px 24px; overflow-y: auto; flex: 1; }
.ios-modal-footer {
    padding: 16px 24px;
    border-top: 0.5px solid #C6C6C8;
    display: flex;
    gap: 8px;
    justify-content: flex-end;
}

@keyframes iosModalUp {
    from { transform: translateY(30px) scale(0.96); opacity: 0; }
    to   { transform: translateY(0) scale(1); opacity: 1; }
}

/* ----------------------------------------------------------------
   13. Animacoes utilitarias
   ---------------------------------------------------------------- */
@keyframes iosFadeIn {
    from { opacity: 0; transform: translateY(8px); }
    to   { opacity: 1; transform: translateY(0); }
}
.ios-animate { animation: iosFadeIn 0.3s ease-out; }
.ios-animate-delay-1 { animation: iosFadeIn 0.3s ease-out 0.05s both; }
.ios-animate-delay-2 { animation: iosFadeIn 0.3s ease-out 0.1s both; }
.ios-animate-delay-3 { animation: iosFadeIn 0.3s ease-out 0.15s both; }

/* ----------------------------------------------------------------
   14. Scrollbar custom
   ---------------------------------------------------------------- */
::-webkit-scrollbar { width: 6px; height: 6px; }
::-webkit-scrollbar-track { background: transparent; }
::-webkit-scrollbar-thumb { background: #C7C7CC; border-radius: 3px; }
::-webkit-scrollbar-thumb:hover { background: #AEAEB2; }

/* ----------------------------------------------------------------
   15. Sidebar (padrao Fase 2 — portal do assinante)
   ---------------------------------------------------------------- */
.ios-sidebar {
    position: fixed;
    top: 0;
    left: 0;
    width: 274px;
    height: 100vh;
    background: rgba(242, 242, 247, 0.95);
    border-right: 0.5px solid #E5E5EA;
    display: flex;
    flex-direction: column;
    padding: 20px 12px 12px;
    z-index: 50;
    overflow-y: auto;
    transition: transform 0.3s ease;
}
.ios-sidebar-nav { display: flex; flex-direction: column; gap: 2px; }
.ios-sidebar-nav a {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 10px 14px;
    border-radius: 10px;
    color: #1c1c1e;
    font-size: 15px;
    transition: background 0.15s;
    text-decoration: none;
}
.ios-sidebar-nav a:hover { background: rgba(0, 0, 0, 0.04); text-decoration: none; }
.ios-sidebar-nav a.active {
    background: #1a2d5a;
    color: #fff;
    font-weight: 600;
}
.ios-sidebar-section {
    padding: 20px 14px 6px;
    font-size: 12px;
    font-weight: 600;
    color: #8E8E93;
    text-transform: uppercase;
    letter-spacing: 0.06em;
}
.ios-sidebar-footer {
    margin-top: auto;
    padding: 12px 14px;
    border-top: 0.5px solid #E5E5EA;
    display: flex;
    align-items: center;
    gap: 12px;
}
.ios-sidebar-avatar {
    width: 36px; height: 36px;
    border-radius: 50%;
    background: rgba(26, 45, 90, 0.1);
    color: #1a2d5a;
    display: flex; align-items: center; justify-content: center;
    font-weight: 600;
    font-size: 15px;
    flex-shrink: 0;
}

.ios-main { margin-left: 274px; padding: 32px; min-height: 100vh; }

.ios-topbar-mobile {
    display: none;
    position: fixed;
    top: 0; left: 0; right: 0;
    height: 52px;
    background: rgba(255, 255, 255, 0.85);
    border-bottom: 0.5px solid #E5E5EA;
    padding: 0 16px;
    align-items: center;
    justify-content: space-between;
    z-index: 40;
}

/* ----------------------------------------------------------------
   16. Mobile (<1024px)
   ---------------------------------------------------------------- */
@media (max-width: 1023px) {
    body { font-size: 15px; }

    .ios-sidebar { transform: translateX(-100%); box-shadow: 0 0 30px rgba(0,0,0,0.2); }
    body.ios-sidebar-open .ios-sidebar { transform: translateX(0); }
    .ios-main { margin-left: 0; padding: 68px 16px 16px; }
    .ios-topbar-mobile { display: flex; }

    .ios-btn   { min-height: 44px; padding: 12px 20px; }
    .ios-btn-sm { min-height: 36px; }
    .ios-input, .ios-textarea, .ios-select { min-height: 44px; font-size: 16px; }

    .ios-h1 { font-size: 28px; }
    .ios-h2 { font-size: 19px; }
    .ios-kpi { font-size: 28px; }

    table { display: block; overflow-x: auto; -webkit-overflow-scrolling: touch; }

    .ios-sidebar-overlay {
        display: none;
        position: fixed; inset: 0;
        background: rgba(0, 0, 0, 0.4);
        z-index: 49;
    }
    body.ios-sidebar-open .ios-sidebar-overlay { display: block; }
}

/* Safe area iPhone notch */
@supports (padding: env(safe-area-inset-top)) {
    .ios-topbar-mobile { padding-top: env(safe-area-inset-top); height: calc(52px + env(safe-area-inset-top)); }
    body { padding-bottom: env(safe-area-inset-bottom); }
}

/* ----------------------------------------------------------------
   17. Utilitarios
   ---------------------------------------------------------------- */
.ios-separator    { height: 0.5px; background: #C6C6C8; border: none; margin: 0; }
.ios-separator-sm { height: 0.5px; background: #C6C6C8; border: none; margin: 8px 0; }

.ios-shadow    { box-shadow: 0 1px 3px rgba(0,0,0,0.08), 0 1px 2px rgba(0,0,0,0.04); }
.ios-shadow-md { box-shadow: 0 4px 14px rgba(0,0,0,0.08); }
.ios-shadow-lg { box-shadow: 0 8px 30px rgba(0,0,0,0.12); }

.ios-icon-btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 36px;
    height: 36px;
    border-radius: 10px;
    border: none;
    background: rgba(118, 118, 128, 0.12);
    color: #1c1c1e;
    cursor: pointer;
    transition: background 0.15s;
}
.ios-icon-btn:hover { background: rgba(118, 118, 128, 0.2); }

/* ----------------------------------------------------------------
   18. Marca TrackMax (branding utilities)
   ---------------------------------------------------------------- */
.tm-brand-gradient {
    background: linear-gradient(135deg, #1a2d5a 0%, #0a1628 100%);
    color: #fff;
}
.tm-brand-text    { color: #1a2d5a; }
.tm-accent-text   { color: #e31937; }
.tm-brand-border  { border-color: #1a2d5a; }

/* Logo wordmark CSS: "Track" navy + "MAX" red, estilo do logo */
.tm-wordmark {
    font-weight: 800;
    letter-spacing: -0.02em;
    font-size: 22px;
}
.tm-wordmark .tm-wordmark-track { color: #1a2d5a; }
.tm-wordmark .tm-wordmark-max   { color: #e31937; }
