:root {
    --ios-bg: #f2f2f7;
    --ios-grouped: #ffffff;
    --ios-separator: rgba(60, 60, 67, 0.12);
    --ios-label: #000000;
    --ios-secondary: rgba(60, 60, 67, 0.6);
    --ios-blue: #007aff;
    --ios-blue-press: #0066d6;
    --ios-green: #34c759;
    --ios-orange: #ff9500;
    --ios-red: #ff3b30;
    --ios-gray: #8e8e93;
    --ios-fill: rgba(120, 120, 128, 0.12);
    --ios-nav: rgba(249, 249, 249, 0.94);
    --radius-group: 12px;
    --font: -apple-system, BlinkMacSystemFont, "SF Pro Text", "SF Pro Display",
        "Helvetica Neue", "PingFang SC", "Noto Sans SC", sans-serif;
}

* { box-sizing: border-box; }

html, body {
    margin: 0;
    min-height: 100%;
    font-family: var(--font);
    color: var(--ios-label);
    background: var(--ios-bg);
    -webkit-font-smoothing: antialiased;
    -webkit-tap-highlight-color: transparent;
}

body.auth {
    min-height: 100vh;
    display: flex;
    flex-direction: column;
    justify-content: center;
    padding: 24px 16px 40px;
}

/* ===== Nav ===== */
.ios-nav {
    position: sticky;
    top: 0;
    z-index: 50;
    background: var(--ios-nav);
    backdrop-filter: saturate(180%) blur(20px);
    -webkit-backdrop-filter: saturate(180%) blur(20px);
    border-bottom: 0.5px solid var(--ios-separator);
    padding: env(safe-area-inset-top, 0) 16px 8px;
}

.ios-nav-bar {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 44px;
}

.ios-nav-bar .nav-side {
    min-width: 64px;
    font-size: 17px;
    color: var(--ios-blue);
    text-decoration: none;
    font-weight: 400;
}

.ios-nav-bar .nav-side.right { text-align: right; }
.ios-nav-bar .nav-title {
    font-size: 17px;
    font-weight: 600;
    text-align: center;
    flex: 1;
}

.ios-large-title {
    margin: 4px 0 8px;
    font-size: 34px;
    font-weight: 700;
    letter-spacing: 0.01em;
    line-height: 1.15;
}

/* ===== Page ===== */
.ios-page {
    width: min(680px, 100%);
    margin: 0 auto;
    padding: 8px 16px 48px;
}

.ios-footnote {
    margin: 8px 16px 20px;
    font-size: 13px;
    line-height: 1.4;
    color: var(--ios-secondary);
}

.ios-section {
    margin-bottom: 28px;
    animation: ios-fade-up 0.38s ease both;
}

.ios-section:nth-of-type(2) { animation-delay: 0.04s; }
.ios-section:nth-of-type(3) { animation-delay: 0.08s; }
.ios-section:nth-of-type(4) { animation-delay: 0.12s; }

@keyframes ios-fade-up {
    from { opacity: 0; transform: translateY(10px); }
    to { opacity: 1; transform: none; }
}

.ios-section-header {
    margin: 0 16px 8px;
    font-size: 13px;
    font-weight: 400;
    color: var(--ios-secondary);
    text-transform: uppercase;
    letter-spacing: 0.02em;
}

.ios-section-footer {
    margin: 8px 16px 0;
    font-size: 13px;
    line-height: 1.35;
    color: var(--ios-secondary);
}

/* ===== Grouped list ===== */
.ios-group {
    background: var(--ios-grouped);
    border-radius: var(--radius-group);
    overflow: hidden;
    box-shadow: 0 0.5px 0 rgba(0, 0, 0, 0.04);
}

.ios-row {
    display: flex;
    align-items: center;
    gap: 12px;
    min-height: 44px;
    padding: 10px 16px;
    position: relative;
    background: var(--ios-grouped);
}

.ios-row + .ios-row::before,
.ios-row + .ios-stack::before,
.ios-stack + .ios-row::before {
    content: "";
    position: absolute;
    left: 16px;
    right: 0;
    top: 0;
    height: 0.5px;
    background: var(--ios-separator);
}

.ios-row .row-label {
    flex: 0 0 96px;
    font-size: 17px;
    color: var(--ios-label);
}

.ios-row .row-field {
    flex: 1;
    min-width: 0;
}

.ios-stack {
    position: relative;
    padding: 10px 16px 12px;
}

.ios-stack .stack-label {
    display: block;
    font-size: 13px;
    color: var(--ios-secondary);
    margin-bottom: 4px;
}

.ios-row input,
.ios-row select,
.ios-stack input,
.ios-stack select {
    width: 100%;
    border: 0;
    outline: none;
    background: transparent;
    font: inherit;
    font-size: 17px;
    color: var(--ios-label);
    padding: 0;
    margin: 0;
    text-align: right;
    appearance: none;
    -webkit-appearance: none;
}

.ios-stack input,
.ios-stack select {
    text-align: left;
    padding: 4px 0;
}

.ios-row input::placeholder,
.ios-stack input::placeholder {
    color: var(--ios-gray);
}

.ios-row select {
    background-image: url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='10' height='6'%3E%3Cpath d='M0 0l5 6 5-6z' fill='%23C7C7CC'/%3E%3C/svg%3E");
    background-repeat: no-repeat;
    background-position: right center;
    padding-right: 16px;
}

/* ===== Buttons ===== */
.ios-btn {
    display: block;
    width: 100%;
    border: 0;
    border-radius: var(--radius-group);
    min-height: 50px;
    margin-top: 16px;
    padding: 12px 16px;
    font: inherit;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
    transition: opacity 0.15s ease, transform 0.12s ease;
}

.ios-btn:active {
    opacity: 0.75;
    transform: scale(0.985);
}

.ios-btn-primary {
    background: var(--ios-blue);
    color: #fff;
}

.ios-btn-primary:hover { background: var(--ios-blue-press); }

.ios-btn-secondary {
    background: var(--ios-grouped);
    color: var(--ios-blue);
    box-shadow: inset 0 0 0 0.5px var(--ios-separator);
}

.ios-btn-danger {
    background: var(--ios-grouped);
    color: var(--ios-red);
    box-shadow: inset 0 0 0 0.5px var(--ios-separator);
}

.ios-btn-plain {
    background: transparent;
    color: var(--ios-blue);
    font-weight: 400;
    min-height: 44px;
    box-shadow: none;
}

.ios-actions {
    display: grid;
    gap: 10px;
    margin-top: 12px;
}

.ios-actions.inline {
    grid-template-columns: 1fr auto;
    align-items: center;
}

.ios-actions.inline input[type="password"] {
    width: 100%;
    min-height: 44px;
    border: 0;
    border-radius: 10px;
    background: var(--ios-grouped);
    padding: 10px 12px;
    font-size: 16px;
    box-shadow: inset 0 0 0 0.5px var(--ios-separator);
}

/* ===== Status chips ===== */
.ios-chip {
    display: inline-flex;
    align-items: center;
    padding: 3px 8px;
    border-radius: 999px;
    font-size: 12px;
    font-weight: 600;
    background: var(--ios-fill);
    color: var(--ios-secondary);
}

.ios-chip.blue { background: rgba(0, 122, 255, 0.12); color: var(--ios-blue); }
.ios-chip.green { background: rgba(52, 199, 89, 0.14); color: #248a3d; }
.ios-chip.orange { background: rgba(255, 149, 0, 0.16); color: #c93400; }
.ios-chip.red { background: rgba(255, 59, 48, 0.14); color: var(--ios-red); }
.ios-chip.gray { background: rgba(142, 142, 147, 0.16); color: #636366; }

/* ===== Rule card ===== */
.ios-rule {
    background: var(--ios-grouped);
    border-radius: var(--radius-group);
    overflow: hidden;
    margin-bottom: 12px;
}

.ios-rule-head {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 8px;
    padding: 14px 16px 10px;
}

.ios-rule-summary {
    border-radius: 0;
    box-shadow: none;
    border-top: 0.5px solid var(--ios-separator);
}

.ios-value {
    text-align: right;
    font-size: 15px;
    color: var(--ios-secondary);
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.ios-rule-toolbar {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    align-items: stretch;
    margin: 0;
    padding: 0;
    border-top: 0.5px solid var(--ios-separator);
    background: #fafafa;
}

.ios-rule-toolbar.cols-2 {
    grid-template-columns: 1fr 1fr;
}

.ios-rule-toolbar.cols-3 {
    grid-template-columns: 1fr 1fr 1fr;
}

.ios-action-form {
    display: flex;
    margin: 0;
    padding: 0;
    min-width: 0;
}

.ios-rule-toolbar > *:not(:last-child) {
    border-right: 0.5px solid var(--ios-separator);
}

.ios-action-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    width: 100%;
    min-height: 48px;
    margin: 0;
    padding: 12px 8px;
    border: 0;
    border-radius: 0;
    background: #fafafa;
    color: var(--ios-blue);
    font-family: var(--font);
    font-size: 16px;
    font-weight: 500;
    letter-spacing: 0.01em;
    cursor: pointer;
    transition: background 0.15s ease, opacity 0.15s ease;
    -webkit-appearance: none;
    appearance: none;
}

.ios-action-btn:hover {
    background: rgba(0, 122, 255, 0.06);
}

.ios-action-btn:active {
    background: rgba(0, 122, 255, 0.12);
    opacity: 0.92;
}

.ios-action-btn.danger {
    color: var(--ios-red);
}

.ios-action-btn.danger:hover {
    background: rgba(255, 59, 48, 0.06);
}

.ios-action-btn.danger:active {
    background: rgba(255, 59, 48, 0.12);
}

.ios-link-btn {
    border: 0;
    background: transparent;
    color: var(--ios-blue);
    font: inherit;
    font-size: 17px;
    padding: 10px 12px;
    cursor: pointer;
}

.ios-link-btn.danger { color: var(--ios-red); }
.ios-link-btn:active { opacity: 0.55; }

.ios-inline-form { display: inline; margin: 0; }

.ios-actions.dual {
    grid-template-columns: 1fr 1fr;
    padding: 0 16px 16px;
    margin-top: 12px;
}

.ios-actions.dual .ios-btn { margin-top: 0; }

.ios-redeploy-box {
    padding: 0 0 8px;
    border-top: 0.5px solid var(--ios-separator);
}

.ios-rule-edit .ios-section-footer {
    margin-top: 10px;
}

.ios-rule-head strong {
    font-size: 20px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.ios-rule-msg {
    margin: 0;
    padding: 0 16px 12px;
    font-size: 13px;
    line-height: 1.4;
    color: var(--ios-secondary);
}

.ios-rule .ios-group {
    border-radius: 0;
    box-shadow: none;
    border-top: 0.5px solid var(--ios-separator);
}

.ios-rule .ios-actions {
    padding: 12px 16px 16px;
    margin-top: 0;
}

/* ===== Alerts ===== */
.ios-alert {
    margin: 0 0 16px;
    padding: 12px 14px;
    border-radius: 12px;
    font-size: 15px;
    line-height: 1.4;
    background: rgba(255, 59, 48, 0.1);
    color: #d70015;
    animation: ios-fade-up 0.3s ease both;
}

.ios-alert.ok {
    background: rgba(52, 199, 89, 0.12);
    color: #248a3d;
}

.ios-empty {
    padding: 28px 16px;
    text-align: center;
    color: var(--ios-secondary);
    font-size: 15px;
    background: var(--ios-grouped);
    border-radius: var(--radius-group);
}

/* ===== Login ===== */
.ios-login {
    width: min(400px, 100%);
    margin: 0 auto;
}

.ios-login-hero {
    text-align: center;
    margin-bottom: 28px;
}

.ios-app-icon {
    width: 84px;
    height: 84px;
    margin: 0 auto 16px;
    border-radius: 22px;
    background:
        linear-gradient(160deg, #5ac8fa 0%, #007aff 55%, #5856d6 120%);
    box-shadow: 0 10px 28px rgba(0, 122, 255, 0.28);
    position: relative;
    animation: ios-icon-pop 0.45s cubic-bezier(0.2, 0.9, 0.3, 1.2) both;
}

.ios-app-icon::after {
    content: "";
    position: absolute;
    inset: 30% 28% 30% 40%;
    border-right: 3px solid #fff;
    border-bottom: 3px solid #fff;
    border-radius: 1px;
    transform: rotate(-45deg);
}

@keyframes ios-icon-pop {
    from { opacity: 0; transform: scale(0.86); }
    to { opacity: 1; transform: scale(1); }
}

.ios-login-hero h1 {
    margin: 0 0 6px;
    font-size: 28px;
    font-weight: 700;
    letter-spacing: -0.02em;
}

.ios-login-hero p {
    margin: 0;
    color: var(--ios-secondary);
    font-size: 15px;
}

/* ===== Deploy modal (iOS sheet) ===== */
.deploy-overlay {
    position: fixed;
    inset: 0;
    display: none;
    align-items: flex-end;
    justify-content: center;
    background: rgba(0, 0, 0, 0.36);
    z-index: 9999;
    padding: 12px;
    padding-bottom: max(12px, env(safe-area-inset-bottom));
}

.deploy-overlay.show {
    display: flex;
    animation: ios-fade-up 0.2s ease both;
}

.deploy-modal {
    width: min(420px, 100%);
    background: rgba(242, 242, 247, 0.96);
    backdrop-filter: blur(24px);
    -webkit-backdrop-filter: blur(24px);
    border-radius: 16px;
    padding: 28px 20px 18px;
    text-align: center;
    box-shadow: 0 16px 40px rgba(0, 0, 0, 0.2);
    animation: ios-sheet 0.28s cubic-bezier(0.2, 0.8, 0.2, 1) both;
}

@keyframes ios-sheet {
    from { transform: translateY(24px); opacity: 0.6; }
    to { transform: none; opacity: 1; }
}

@media (min-width: 640px) {
    .deploy-overlay { align-items: center; }
}

.deploy-modal h3 {
    margin: 14px 0 6px;
    font-size: 20px;
    font-weight: 700;
}

.deploy-modal p {
    margin: 0;
    color: var(--ios-secondary);
    font-size: 15px;
    line-height: 1.45;
    word-break: break-word;
}

.deploy-spinner {
    width: 36px;
    height: 36px;
    margin: 0 auto;
    border: 3px solid rgba(60, 60, 67, 0.12);
    border-top-color: var(--ios-blue);
    border-radius: 50%;
    animation: deploy-spin 0.7s linear infinite;
}

.deploy-icon {
    width: 52px;
    height: 52px;
    margin: 0 auto;
    border-radius: 50%;
    display: none;
    align-items: center;
    justify-content: center;
    font-size: 26px;
    font-weight: 700;
    color: #fff;
}

.deploy-overlay.is-success .deploy-icon { background: var(--ios-green); }
.deploy-overlay.is-failed .deploy-icon { background: var(--ios-red); }
.deploy-overlay.is-success #deploy-title { color: #248a3d; }
.deploy-overlay.is-failed #deploy-title { color: var(--ios-red); }

.deploy-close,
#deploy-close {
    margin-top: 18px;
    width: 100%;
    border: 0;
    border-radius: 12px;
    min-height: 50px;
    background: var(--ios-blue);
    color: #fff;
    font: inherit;
    font-size: 17px;
    font-weight: 600;
    cursor: pointer;
}

.deploy-overlay.is-failed .deploy-close,
.deploy-overlay.is-failed #deploy-close {
    background: var(--ios-red);
}

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

/* legacy class bridges used by older markup leftovers */
.card, .wrap, .top, .muted, .link, .tag, .alert, .remote-box { }
code {
    font-family: ui-monospace, SFMono-Regular, Menlo, Consolas, monospace;
    font-size: 0.92em;
}
