* {
    box-sizing: border-box;
}

html {
    -webkit-text-size-adjust: 100%;
}

body {
    margin: 0;

    background: #f3f4f6;
    color: #111827;

    font-family:
        -apple-system,
        BlinkMacSystemFont,
        "Segoe UI",
        Arial,
        sans-serif;
}

button,
input,
select {
    font: inherit;
}

button,
select,
a {
    touch-action: manipulation;
}

button {
    cursor: pointer;
}

input,
select {
    min-height: 52px;

    border: 1px solid #d1d5db;

    border-radius: 12px;

    background: white;

    color: #111827;

    outline: none;
}

input:focus,
select:focus {
    border-color: #111827;

    box-shadow:
        0 0 0 3px
        rgba(17, 24, 39, .08);
}


/* =====================================================
   HEADER
   ===================================================== */

.app-header {
    position: sticky;

    top: 0;

    z-index: 100;

    background: #111827;

    color: white;
}

.app-header-inner {
    min-height: 68px;

    display: flex;

    align-items: center;

    gap: 24px;

    max-width: 1600px;

    margin: auto;

    padding:
        env(safe-area-inset-top)
        22px
        0;
}

.app-logo {
    display: flex;

    flex-direction: column;

    flex-shrink: 0;

    color: white;

    text-decoration: none;

    font-size: 20px;
    font-weight: 900;

    line-height: .9;
}

.app-logo span {
    margin-top: 5px;

    color: #9ca3af;

    font-size: 10px;

    letter-spacing: .16em;
}


/* =====================================================
   NAVIGATION
   ===================================================== */

.module-nav {
    flex: 1;

    display: flex;

    gap: 5px;

    overflow-x: auto;

    scrollbar-width: none;
}

.module-nav::-webkit-scrollbar {
    display: none;
}

.module-nav a {
    min-height: 44px;

    display: flex;

    align-items: center;

    padding: 0 17px;

    border-radius: 11px;

    color: #d1d5db;

    text-decoration: none;

    font-size: 15px;
    font-weight: 650;

    white-space: nowrap;
}

.module-nav a:hover {
    background: #1f2937;

    color: white;
}

.module-nav a.active {
    background: white;

    color: #111827;
}


/* =====================================================
   SYSTEM STATUS
   ===================================================== */

.system-status {
    flex-shrink: 0;
    display: flex;
    align-items: center;
    gap: 7px;
}

.status-pill {
    min-height: 34px;

    display: flex;

    align-items: center;

    gap: 7px;

    padding: 0 10px;

    border: 1px solid #374151;

    border-radius: 999px;

    background: #1f2937;

    color: #d1d5db;

    font-size: 12px;

    white-space: nowrap;
}

.status-led {
    width: 9px;
    height: 9px;

    display: block;

    border-radius: 50%;

    background: #9ca3af;

    box-shadow:
        0 0 0 3px
        rgba(156, 163, 175, .12);
}

.status-pill.online .status-led {
    background: #22c55e;

    box-shadow:
        0 0 0 3px
        rgba(34, 197, 94, .15);
}

.status-pill.offline .status-led {
    background: #ef4444;

    box-shadow:
        0 0 0 3px
        rgba(239, 68, 68, .15);
}

.status-pill.checking .status-led {
    background: #9ca3af;
}

.sync-pill {
    min-height: 34px;
    display: flex;
    align-items: center;
    gap: 5px;
    padding: 0 4px 0 10px;
    border: 1px solid #374151;
    border-radius: 999px;
    background: #1f2937;
    color: #d1d5db;
    white-space: nowrap;
}

.sync-countdown {
    min-width: 62px;
    font-size: 12px;
    font-variant-numeric: tabular-nums;
    text-align: center;
}

.sync-button {
    width: 28px;
    height: 28px;
    min-height: 28px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0;
    border: 0;
    border-radius: 50%;
    background: transparent;
    color: #d1d5db;
}

.sync-button:hover {
    background: #374151;
    color: #fff;
}

.sync-button:disabled {
    opacity: .6;
    cursor: default;
}

.sync-button svg {
    width: 17px;
    height: 17px;
    fill: none;
    stroke: currentColor;
    stroke-width: 1.8;
    stroke-linecap: round;
    stroke-linejoin: round;
}

.sync-pill.running .sync-button svg {
    animation: toolset-sync-spin .9s linear infinite;
}

.sync-pill.error {
    border-color: rgba(248, 113, 113, .72);
}

@keyframes toolset-sync-spin {
    to { transform: rotate(360deg); }
}


/* =====================================================
   ACCOUNT
   ===================================================== */

.account-area {
    display: flex;

    align-items: center;

    gap: 12px;

    flex-shrink: 0;

    font-size: 13px;

    color: #d1d5db;
}

.account-area form {
    margin: 0;
}

.account-area button {
    min-height: 38px;

    padding: 0 12px;

    border:
        1px solid
        #4b5563;

    border-radius: 9px;

    background: transparent;

    color: white;
}


/* =====================================================
   GENERAL LAYOUT
   ===================================================== */

.page {
    max-width: 1600px;

    margin: auto;

    padding: 26px;
}

.page-title {
    margin: 0;

    font-size: 28px;
}

.page-subtitle {
    margin:
        5px
        0
        22px;

    color: #6b7280;
}

.card {
    background: white;

    border: 1px solid #e5e7eb;

    border-radius: 18px;

    box-shadow:
        0 3px 15px
        rgba(0, 0, 0, .035);
}

.status-online {
    color: #047857;
}

.status-offline {
    color: #b45309;
}


/* =====================================================
   MOBILE
   ===================================================== */

@media(max-width:900px) {

    .app-header-inner {
        gap: 12px;

        padding-left: 12px;
        padding-right: 12px;
    }

    .account-area > span {
        display: none;
    }

    .status-label {
        display: none;
    }

    .status-pill {
        width: 34px;

        justify-content: center;

        padding: 0;
    }

    .sync-pill {
        padding-left: 8px;
    }

    .sync-countdown {
        min-width: 52px;
        font-size: 11px;
    }

}


@media(max-width:700px) {

    .app-header-inner {
        min-height: 62px;
    }

    .app-logo {
        font-size: 16px;
    }

    .module-nav {
        gap: 2px;
    }

    .module-nav a {
        min-height: 40px;

        padding: 0 11px;

        font-size: 13px;
    }

    .account-area button {
        padding: 0 8px;

        font-size: 11px;
    }

    .page {
        padding: 15px;
    }

}


@media(max-width:520px) {

    .app-logo span {
        display: none;
    }

    .app-logo {
        font-size: 14px;
    }

    .module-nav a {
        padding: 0 9px;

        font-size: 12px;
    }

}

/* =====================================================
   MOBILE HEADER MENU
   ===================================================== */

.mobile-menu-toggle,
.mobile-nav-extras {
    display: none;
}

@media (max-width: 900px) {
    .app-header-inner {
        position: relative;
        min-height: 62px;
        gap: 10px;
        padding-left: 14px;
        padding-right: 14px;
    }

    .app-logo {
        order: 1;
        margin-right: auto;
    }

    .system-status {
        order: 2;
        gap: 5px;
    }

    .status-pill {
        min-width: 34px;
        padding: 0 9px;
    }

    .status-pill .status-label {
        display: none;
    }

    .sync-pill {
        min-height: 34px;
        padding-left: 8px;
    }

    .sync-countdown {
        min-width: 50px;
        font-size: 11px;
    }

    .mobile-menu-toggle {
        order: 3;
        width: 44px;
        height: 44px;
        flex: 0 0 44px;
        display: inline-flex;
        flex-direction: column;
        align-items: center;
        justify-content: center;
        gap: 5px;
        padding: 0;
        border: 1px solid #374151;
        border-radius: 11px;
        background: #1f2937;
        color: white;
    }

    .mobile-menu-toggle span {
        width: 20px;
        height: 2px;
        display: block;
        border-radius: 999px;
        background: currentColor;
        transition: transform .16s ease, opacity .16s ease;
    }

    .app-header.menu-open .mobile-menu-toggle span:nth-child(1) {
        transform: translateY(7px) rotate(45deg);
    }

    .app-header.menu-open .mobile-menu-toggle span:nth-child(2) {
        opacity: 0;
    }

    .app-header.menu-open .mobile-menu-toggle span:nth-child(3) {
        transform: translateY(-7px) rotate(-45deg);
    }

    .theme-area,
    .account-area {
        display: none;
    }

    .module-nav {
        position: absolute;
        top: 100%;
        left: 0;
        right: 0;
        z-index: 160;
        display: none;
        max-height: calc(100vh - 62px - env(safe-area-inset-top));
        overflow-y: auto;
        flex-direction: column;
        gap: 4px;
        padding: 10px 14px 16px;
        border-top: 1px solid #374151;
        background: #111827;
        box-shadow: 0 16px 28px rgba(0, 0, 0, .24);
    }

    .app-header.menu-open .module-nav {
        display: flex;
    }

    .module-nav a {
        width: 100%;
        min-height: 48px;
        justify-content: flex-start;
        padding: 0 15px;
        border-radius: 10px;
        font-size: 15px;
    }

    .mobile-nav-extras {
        display: grid;
        grid-template-columns: 1fr 1fr;
        gap: 8px;
        margin-top: 6px;
        padding-top: 12px;
        border-top: 1px solid #374151;
    }

    .mobile-nav-user {
        grid-column: 1 / -1;
        padding: 2px 4px 6px;
        color: #9ca3af;
        font-size: 12px;
        font-weight: 700;
    }

    .mobile-theme-toggle,
    .mobile-logout-button {
        width: 100%;
        min-height: 44px;
        justify-content: center;
        border: 1px solid #374151;
        border-radius: 10px;
        background: #1f2937;
        color: white;
    }

    .mobile-logout-form {
        margin: 0;
    }

    .mobile-logout-button {
        padding: 0 12px;
    }
}

@media (max-width: 430px) {
    .app-header-inner {
        padding-left: 10px;
        padding-right: 10px;
    }

    .app-logo {
        font-size: 14px;
    }

    .sync-countdown {
        min-width: 45px;
        font-size: 10px;
    }

    .status-pill {
        display: none;
    }
}
