:root {
    --bg: #0f172a;
    --surface: #111827;
    --card: #1f2937;
    --border: #374151;
    --text: #f9fafb;
    --muted: #9ca3af;
    --primary: #3b82f6;
    --primary-hover: #2563eb;
    --danger: #ef4444;
    --success: #22c55e;
    --warning: #f59e0b;
}

* {
    box-sizing: border-box;
}

html {
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

body {
    margin: 0;
    font-family: Vazirmatn, Tahoma, sans-serif;
    font-weight: 400;
    background: linear-gradient(180deg, #0b1220 0%, var(--bg) 100%);
    color: var(--text);
    min-height: 100vh;
    line-height: 1.6;
}

.container {
    width: min(1200px, calc(100% - 2rem));
    margin: 0 auto;
}

.navbar {
    background: rgba(17, 24, 39, 0.95);
    border-bottom: 1px solid var(--border);
    backdrop-filter: blur(8px);
    position: sticky;
    top: 0;
    z-index: 10;
}

.nav-inner {
    display: flex;
    align-items: center;
    justify-content: space-between;
    min-height: 64px;
}

.brand {
    color: var(--text);
    text-decoration: none;
    font-weight: 700;
}

.nav-links {
    display: flex;
    gap: 1rem;
}

.nav-links a {
    color: var(--muted);
    text-decoration: none;
}

.nav-links a:hover {
    color: var(--text);
}

main.container {
    padding: 2rem 0 4rem;
}

.page-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.5rem;
}

.page-header h1,
.card h1 {
    margin: 0 0 0.5rem;
    font-weight: 700;
}

.muted {
    color: var(--muted);
    margin: 0;
}

.actions {
    display: flex;
    gap: 0.75rem;
    flex-wrap: wrap;
}

.card {
    background: var(--card);
    border: 1px solid var(--border);
    border-radius: 16px;
    padding: 1.5rem;
    box-shadow: 0 10px 30px rgba(0, 0, 0, 0.25);
}

.card-narrow {
    max-width: 560px;
    margin: 0 auto;
}

.form {
    display: grid;
    gap: 1rem;
}

label {
    display: grid;
    gap: 0.5rem;
    font-size: 0.95rem;
}

input[type="text"],
input[type="password"],
input[type="number"],
input[type="datetime-local"] {
    width: 100%;
    padding: 0.75rem 0.9rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

input:disabled {
    opacity: 0.7;
}

.hint {
    color: var(--muted);
    font-size: 0.85rem;
}

.checkbox {
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.btn {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    padding: 0.65rem 1rem;
    border-radius: 10px;
    border: 1px solid transparent;
    text-decoration: none;
    color: var(--text);
    background: var(--surface);
    cursor: pointer;
    font: inherit;
    font-weight: 500;
}

.btn-primary {
    background: var(--primary);
}

.btn-primary:hover {
    background: var(--primary-hover);
}

.btn-secondary {
    border-color: var(--border);
}

.btn-danger {
    background: rgba(239, 68, 68, 0.15);
    border-color: rgba(239, 68, 68, 0.4);
    color: #fecaca;
}

.btn-small {
    padding: 0.35rem 0.65rem;
    font-size: 0.85rem;
}

.alert {
    padding: 1rem 1.25rem;
    border-radius: 12px;
    margin-bottom: 1rem;
    border: 1px solid transparent;
}

.alert-success {
    background: rgba(34, 197, 94, 0.12);
    border-color: rgba(34, 197, 94, 0.35);
}

.alert-danger {
    background: rgba(239, 68, 68, 0.12);
    border-color: rgba(239, 68, 68, 0.35);
}

.table-wrap {
    overflow-x: auto;
}

table {
    width: 100%;
    border-collapse: collapse;
}

th,
td {
    padding: 0.85rem 0.75rem;
    border-bottom: 1px solid var(--border);
    text-align: right;
    vertical-align: middle;
}

th {
    color: var(--muted);
    font-weight: 600;
}

.empty {
    text-align: center;
    color: var(--muted);
}

.row-actions {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

/* Dashboard */
.dashboard-card {
    padding-top: 1.15rem;
}

.dashboard-toolbar {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-bottom: 1.15rem;
    padding-bottom: 1rem;
    border-bottom: 1px solid var(--border);
}

.dashboard-search {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    gap: 0.65rem;
    flex: 1;
    min-width: min(100%, 320px);
}

.search-field {
    position: relative;
    flex: 1;
    min-width: 200px;
}

.search-icon {
    position: absolute;
    top: 50%;
    right: 0.85rem;
    transform: translateY(-50%);
    color: var(--muted);
    pointer-events: none;
    font-size: 1rem;
}

.search-field input[type="search"] {
    width: 100%;
    padding: 0.7rem 2.25rem 0.7rem 0.9rem;
    border-radius: 10px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

.search-field input[type="search"]:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px rgba(37, 99, 235, 0.18);
}

.per-page-select {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    font-size: 0.85rem;
}

.per-page-select select {
    padding: 0.55rem 0.65rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
}

.dashboard-meta {
    font-size: 0.88rem;
    white-space: nowrap;
}

.accounts-table .col-id {
    color: var(--muted);
    font-size: 0.88rem;
    width: 3rem;
}

.accounts-table .col-name strong {
    font-weight: 600;
}

.accounts-table .ip-code {
    font-size: 0.82rem;
}

.accounts-table .col-compact {
    font-size: 0.88rem;
    white-space: nowrap;
}

.accounts-table .col-expiry {
    font-size: 0.86rem;
    max-width: 11rem;
}

.accounts-table .col-actions {
    min-width: 280px;
}

.action-bar {
    display: flex;
    flex-direction: column;
    gap: 0.45rem;
    align-items: flex-start;
}

.action-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.35rem;
}

.action-group-tools {
    padding-top: 0.15rem;
}

.action-chip {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.5rem;
    padding: 0.32rem 0.62rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: rgba(255, 255, 255, 0.04);
    color: var(--text);
    font-size: 0.78rem;
    font-weight: 600;
    text-decoration: none;
    cursor: pointer;
    transition: background 0.15s ease, border-color 0.15s ease, transform 0.1s ease;
    line-height: 1.2;
}

button.action-chip {
    font: inherit;
}

.action-chip:hover {
    background: rgba(255, 255, 255, 0.08);
    border-color: rgba(255, 255, 255, 0.18);
    transform: translateY(-1px);
}

.action-chip-sub {
    background: rgba(37, 99, 235, 0.14);
    border-color: rgba(59, 130, 246, 0.35);
    color: #bfdbfe;
}

.action-chip-qr {
    background: rgba(168, 85, 247, 0.12);
    border-color: rgba(168, 85, 247, 0.32);
    color: #e9d5ff;
}

.action-chip-dl {
    background: rgba(20, 184, 166, 0.12);
    border-color: rgba(45, 212, 191, 0.32);
    color: #99f6e4;
}

.action-chip-edit {
    background: rgba(255, 255, 255, 0.06);
}

.action-chip-ok {
    background: rgba(34, 197, 94, 0.12);
    border-color: rgba(34, 197, 94, 0.35);
    color: #86efac;
}

.action-chip-warn {
    background: rgba(245, 158, 11, 0.12);
    border-color: rgba(245, 158, 11, 0.35);
    color: #fcd34d;
}

.action-chip-muted {
    color: var(--muted);
}

.action-chip-danger {
    background: rgba(239, 68, 68, 0.1);
    border-color: rgba(239, 68, 68, 0.35);
    color: #fecaca;
}

.action-chip-danger:hover {
    background: rgba(239, 68, 68, 0.2);
}

.pagination {
    display: flex;
    flex-wrap: wrap;
    align-items: center;
    justify-content: center;
    gap: 0.35rem;
    margin-top: 1.25rem;
    padding-top: 1rem;
    border-top: 1px solid var(--border);
}

.page-link {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    min-width: 2.2rem;
    height: 2.2rem;
    padding: 0 0.55rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    text-decoration: none;
    font-size: 0.88rem;
}

.page-link:hover {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.12);
}

.page-link.is-active {
    background: var(--primary);
    border-color: var(--primary);
    color: #fff;
    font-weight: 600;
}

.page-link.is-disabled {
    opacity: 0.45;
    cursor: default;
}

.page-ellipsis {
    color: var(--muted);
    padding: 0 0.25rem;
}

.inline-form {
    display: inline;
}

.badge {
    display: inline-block;
    padding: 0.2rem 0.55rem;
    border-radius: 999px;
    font-size: 0.8rem;
}

.badge-success {
    background: rgba(34, 197, 94, 0.15);
    color: #86efac;
}

.badge-info {
    background: rgba(59, 130, 246, 0.15);
    color: #93c5fd;
}

.badge-danger {
    background: rgba(239, 68, 68, 0.15);
    color: #fca5a5;
}

.badge-warning {
    background: rgba(245, 158, 11, 0.15);
    color: #fcd34d;
}

.badge-muted {
    background: rgba(156, 163, 175, 0.15);
    color: #d1d5db;
}

code {
    background: rgba(255, 255, 255, 0.05);
    padding: 0.15rem 0.4rem;
    border-radius: 6px;
}

.footer {
    padding: 1.5rem 0 2rem;
    color: var(--muted);
    text-align: center;
}

.view-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(280px, 1fr));
    gap: 1.5rem;
    margin-bottom: 1.5rem;
}

.qr-card h2,
.card h2 {
    margin-top: 0;
}

.qr-wrap {
    display: flex;
    justify-content: center;
    padding: 1rem;
    background: #fff;
    border-radius: 12px;
}

.qr-wrap img {
    display: block;
    max-width: 100%;
    height: auto;
}

.details {
    display: grid;
    grid-template-columns: 120px 1fr;
    gap: 0.75rem 1rem;
    margin: 0;
}

.details dt {
    color: var(--muted);
}

.details dd {
    margin: 0;
}

.config-block {
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    padding: 1rem;
    overflow-x: auto;
    white-space: pre-wrap;
    word-break: break-all;
    margin: 0;
    direction: ltr;
    text-align: left;
}

.subscribe-link-box {
    display: flex;
    gap: 0.5rem;
    margin-top: 0.75rem;
}

.subscribe-link-box input {
    flex: 1;
    min-width: 0;
    padding: 0.6rem 0.75rem;
    border-radius: 8px;
    border: 1px solid var(--border);
    background: var(--surface);
    color: var(--text);
    font-size: 0.82rem;
    direction: ltr;
    text-align: left;
}

.online-status {
    display: inline-flex;
    align-items: center;
    gap: 0.45rem;
    white-space: nowrap;
}

.online-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: #6b7280;
    flex-shrink: 0;
}

.online-dot.is-online {
    background: #22c55e;
    box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.6);
    animation: online-pulse 2s infinite;
}

.online-dot.is-offline {
    background: #6b7280;
}

.online-dot.online-dot-pending {
    background: #9ca3af;
    animation: online-blink 1.2s infinite;
}

.online-label {
    font-size: 0.88rem;
}

.online-meta {
    display: block;
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 0.15rem;
}

.connection-live {
    display: flex;
    align-items: center;
    gap: 0.75rem;
    padding: 1rem 1.15rem;
    border-radius: 12px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px solid var(--border);
    margin-bottom: 1rem;
}

.connection-live .online-dot {
    width: 14px;
    height: 14px;
}

.connection-live .badge-lg {
    margin-right: auto;
}

.connection-live-text {
    flex: 1;
}

.connection-live-title {
    font-weight: 700;
    font-size: 1.05rem;
}

.connection-live-meta {
    color: var(--muted);
    font-size: 0.85rem;
    margin-top: 0.2rem;
}

.live-indicator-note {
    font-size: 0.78rem;
    color: var(--muted);
    margin-top: 0.5rem;
}

@keyframes online-pulse {
    0% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0.55);
    }
    70% {
        box-shadow: 0 0 0 8px rgba(34, 197, 94, 0);
    }
    100% {
        box-shadow: 0 0 0 0 rgba(34, 197, 94, 0);
    }
}

@keyframes online-blink {
    0%, 100% { opacity: 1; }
    50% { opacity: 0.35; }
}

/* Edit account page */
.badge-lg {
    font-size: 0.9rem;
    padding: 0.35rem 0.75rem;
    white-space: nowrap;
    display: inline-block;
    margin-top: 0.65rem;
}

.edit-layout {
    display: grid;
    grid-template-columns: minmax(260px, 300px) minmax(0, 1fr);
    gap: 1.5rem;
    align-items: start;
}

.edit-sidebar-title,
.form-section-title {
    margin: 0 0 1rem;
    font-size: 0.95rem;
    font-weight: 600;
    color: var(--muted);
}

.edit-sidebar-title {
    font-size: 1.05rem;
    color: var(--text);
}

.edit-online {
    display: flex;
    align-items: center;
    gap: 0.65rem;
    padding: 0.85rem 1rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 12px;
    margin-bottom: 1.25rem;
}

.edit-online-label {
    font-weight: 600;
    font-size: 0.95rem;
}

.edit-online-meta {
    font-size: 0.82rem;
    margin-top: 0.15rem;
}

.edit-details {
    margin-bottom: 1.25rem;
}

.edit-volume-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    margin-bottom: 0.65rem;
    font-size: 0.9rem;
}

.edit-volume-meta {
    margin: 0.5rem 0 0;
    font-size: 0.82rem;
}

.progress-track {
    height: 10px;
    background: var(--surface);
    border-radius: 999px;
    overflow: hidden;
    border: 1px solid var(--border);
}

.progress-fill {
    height: 100%;
    background: linear-gradient(90deg, #2563eb, #3b82f6);
    border-radius: 999px;
    transition: width 0.3s ease;
}

.progress-fill.progress-warning {
    background: linear-gradient(90deg, #d97706, #f59e0b);
}

.progress-fill.progress-danger {
    background: linear-gradient(90deg, #dc2626, #ef4444);
}

.form-sections {
    gap: 0;
}

.form-section {
    padding: 1.35rem 0;
    border-bottom: 1px solid var(--border);
}

.form-section-last {
    border-bottom: none;
    padding-bottom: 0.5rem;
}

.form-grid-2 {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 1rem;
}

.readonly-field {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
    margin-top: 1rem;
    padding: 0.85rem 1rem;
    border-radius: 10px;
    background: rgba(255, 255, 255, 0.03);
    border: 1px dashed var(--border);
}

.readonly-field-label {
    color: var(--muted);
    font-size: 0.88rem;
}

.readonly-field-value {
    font-weight: 600;
    direction: ltr;
}

.expiry-mode-tabs {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 0.75rem;
    margin-bottom: 1rem;
}

.expiry-mode-tab {
    position: relative;
    display: grid;
    gap: 0.2rem;
    padding: 0.9rem 1rem;
    border-radius: 12px;
    border: 1px solid var(--border);
    background: var(--surface);
    cursor: pointer;
    transition: border-color 0.15s ease, background 0.15s ease;
}

.expiry-mode-tab input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.expiry-mode-tab.is-active {
    border-color: var(--primary);
    background: rgba(37, 99, 235, 0.12);
}

.expiry-mode-tab-title {
    font-weight: 600;
    font-size: 0.92rem;
}

.expiry-mode-tab-desc {
    color: var(--muted);
    font-size: 0.78rem;
}

.expiry-panel {
    padding: 0.25rem 0 0;
}

.expiry-note {
    margin: 0.5rem 0 0;
}

.toggle-field {
    display: flex;
    align-items: center;
    gap: 0.85rem;
    padding: 0.85rem 1rem;
    border-radius: 12px;
    background: var(--surface);
    border: 1px solid var(--border);
    cursor: pointer;
}

.toggle-input {
    position: absolute;
    opacity: 0;
    pointer-events: none;
}

.toggle-switch {
    position: relative;
    width: 44px;
    height: 24px;
    flex-shrink: 0;
    border-radius: 999px;
    background: rgba(255, 255, 255, 0.12);
    border: 1px solid var(--border);
    transition: background 0.2s ease;
}

.toggle-switch::after {
    content: "";
    position: absolute;
    top: 2px;
    right: 2px;
    width: 18px;
    height: 18px;
    border-radius: 50%;
    background: #fff;
    transition: transform 0.2s ease;
}

.toggle-input:checked + .toggle-switch {
    background: var(--primary);
    border-color: var(--primary);
}

.toggle-input:checked + .toggle-switch::after {
    transform: translateX(-20px);
}

.toggle-label {
    display: grid;
    gap: 0.15rem;
}

.form-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    padding-top: 1.25rem;
    margin-top: 0.25rem;
    border-top: 1px solid var(--border);
}

@media (max-width: 768px) {
    .page-header,
    .nav-inner {
        flex-direction: column;
        align-items: flex-start;
    }

    .row-actions {
        min-width: 220px;
    }

    .accounts-table .col-actions {
        min-width: 200px;
    }

    .dashboard-toolbar {
        flex-direction: column;
        align-items: stretch;
    }

    .dashboard-search {
        width: 100%;
    }

    .pagination {
        justify-content: flex-start;
    }

    .edit-layout {
        grid-template-columns: 1fr;
    }

    .form-grid-2,
    .expiry-mode-tabs {
        grid-template-columns: 1fr;
    }

    .form-actions {
        flex-direction: column-reverse;
    }

    .form-actions .btn {
        width: 100%;
    }
}

/* Create account page */
.create-page .page-header h1 {
    margin-bottom: 0.25rem;
}

.create-badge {
    display: inline-flex;
    align-items: center;
    margin-top: 0.55rem;
    padding: 0.25rem 0.7rem;
    border-radius: 999px;
    font-size: 0.75rem;
    font-weight: 600;
    color: #86efac;
    background: rgba(34, 197, 94, 0.12);
    border: 1px solid rgba(34, 197, 94, 0.28);
}

.create-sidebar {
    position: sticky;
    top: 5rem;
}

.create-tips {
    list-style: none;
    padding: 0;
    margin: 0 0 1rem;
    display: grid;
    gap: 0.6rem;
}

.create-tip {
    display: flex;
    align-items: flex-start;
    gap: 0.65rem;
    padding: 0.75rem 0.85rem;
    background: var(--surface);
    border: 1px solid var(--border);
    border-radius: 10px;
    font-size: 0.86rem;
    color: var(--muted);
    line-height: 1.5;
}

.create-tip-icon {
    flex-shrink: 0;
    min-width: 2.1rem;
    height: 1.65rem;
    padding: 0 0.35rem;
    border-radius: 7px;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    background: rgba(59, 130, 246, 0.14);
    color: #93c5fd;
    font-size: 0.68rem;
    font-weight: 700;
    letter-spacing: 0.02em;
}

.create-ref-block {
    padding: 0.9rem 1rem;
    background: var(--surface);
    border: 1px dashed rgba(148, 163, 184, 0.35);
    border-radius: 10px;
    margin-bottom: 0.75rem;
}

.create-ref-block:last-child {
    margin-bottom: 0;
}

.create-ref-block h4 {
    margin: 0 0 0.65rem;
    font-size: 0.82rem;
    font-weight: 600;
    color: var(--muted);
    text-transform: uppercase;
    letter-spacing: 0.04em;
}

.create-ref-grid {
    margin: 0;
    display: grid;
    gap: 0.45rem;
}

.create-ref-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 0.75rem;
    font-size: 0.84rem;
}

.create-ref-row dt {
    margin: 0;
    color: var(--muted);
}

.create-ref-row dd {
    margin: 0;
    color: var(--text);
    text-align: left;
    direction: ltr;
}

.create-ref-row code {
    font-size: 0.78rem;
}

.create-page .edit-form-card {
    background: linear-gradient(180deg, rgba(59, 130, 246, 0.04) 0%, var(--card) 120px);
}

.btn-create {
    min-width: 9rem;
    box-shadow: 0 4px 14px rgba(37, 99, 235, 0.35);
}

.create-submit-hint {
    margin: 0.65rem 0 0;
    text-align: center;
    font-size: 0.82rem;
    color: var(--muted);
}

@media (max-width: 768px) {
    .create-sidebar {
        position: static;
    }
}
