/* ============================
   CSS Variables & Reset
   ============================ */
:root {
    --primary: #6c5ce7;
    --primary-light: #a29bfe;
    --primary-dark: #5a4bd1;
    --green: #00b894;
    --green-bg: #e6f9f3;
    --blue: #0984e3;
    --blue-bg: #e3f2fd;
    --red: #d63031;
    --red-bg: #fdecea;
    --orange: #e17055;
    --orange-bg: #fef3e8;
    --bg: #f0f2f5;
    --card-bg: #ffffff;
    --text-primary: #2d3436;
    --text-secondary: #636e72;
    --text-muted: #b2bec3;
    --border: #e9ecef;
    --shadow-sm: 0 1px 3px rgba(0, 0, 0, 0.06);
    --shadow-md: 0 4px 12px rgba(0, 0, 0, 0.08);
    --shadow-lg: 0 8px 30px rgba(0, 0, 0, 0.12);
    --radius-sm: 8px;
    --radius-md: 12px;
    --radius-lg: 16px;
    --radius-xl: 20px;
    --transition: all 0.3s cubic-bezier(0.4, 0, 0.2, 1);
}

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

body {
    font-family: 'Inter', 'Noto Sans SC', -apple-system, BlinkMacSystemFont, sans-serif;
    background: var(--bg);
    color: var(--text-primary);
    min-height: 100vh;
    -webkit-font-smoothing: antialiased;
    -moz-osx-font-smoothing: grayscale;
}

/* ============================
   Container
   ============================ */
.container {
    max-width: 960px;
    margin: 0 auto;
    padding: 40px 20px 60px;
}

/* ============================
   Header
   ============================ */
.header {
    text-align: center;
    padding: 36px 20px 28px;
    background: var(--card-bg);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-md);
    margin-bottom: 20px;
}

.header-title {
    font-size: 28px;
    font-weight: 800;
    background: linear-gradient(135deg, var(--primary), #e17055);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    background-clip: text;
    margin-bottom: 8px;
    letter-spacing: -0.5px;
}

.header-subtitle {
    font-size: 14px;
    color: var(--text-secondary);
    font-weight: 400;
}

/* ============================
   Status Bar
   ============================ */
.status-bar {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 8px;
    padding: 14px 20px;
    background: var(--card-bg);
    border-radius: var(--radius-md);
    box-shadow: var(--shadow-sm);
    margin-bottom: 20px;
    flex-wrap: wrap;
}

.status-dot {
    width: 10px;
    height: 10px;
    border-radius: 50%;
    background: var(--green);
    box-shadow: 0 0 8px rgba(0, 184, 148, 0.5);
    animation: pulse 2s ease-in-out infinite;
}

@keyframes pulse {

    0%,
    100% {
        box-shadow: 0 0 8px rgba(0, 184, 148, 0.5);
    }

    50% {
        box-shadow: 0 0 16px rgba(0, 184, 148, 0.8);
    }
}

.status-text {
    font-size: 14px;
    color: var(--text-secondary);
}

.status-text strong {
    color: var(--text-primary);
    font-weight: 700;
}

.status-divider {
    color: var(--text-muted);
    font-size: 14px;
}

/* ============================
   Tab Navigation
   ============================ */
.tab-nav {
    display: grid;
    grid-template-columns: repeat(3, 1fr);
    gap: 0;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-md);
    margin-bottom: 24px;
    overflow: hidden;
}

.tab-btn {
    display: flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    padding: 16px 12px;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 15px;
    font-weight: 600;
    color: var(--text-secondary);
    cursor: pointer;
    transition: var(--transition);
    position: relative;
}

.tab-btn:hover {
    background: rgba(108, 92, 231, 0.05);
    color: var(--primary);
}

.tab-btn.active {
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
}

.tab-btn.active:hover {
    background: linear-gradient(135deg, var(--primary-dark), #4a3db8);
}

.tab-icon {
    font-size: 16px;
}

/* ============================
   Tab Content
   ============================ */
.tab-content {
    display: none;
    animation: fadeIn 0.35s ease;
}

.tab-content.active {
    display: block;
}

@keyframes fadeIn {
    from {
        opacity: 0;
        transform: translateY(8px);
    }

    to {
        opacity: 1;
        transform: translateY(0);
    }
}

/* ============================
   Section Header
   ============================ */
.section-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 16px;
    padding: 0 4px;
    flex-wrap: wrap;
    gap: 8px;
}

.section-title {
    font-size: 18px;
    font-weight: 700;
    color: var(--text-primary);
}

.section-hint {
    font-size: 13px;
    color: var(--text-muted);
}

/* ============================
   App List
   ============================ */
.app-list {
    display: flex;
    flex-direction: column;
    gap: 12px;
}

/* ============================
   App Card
   ============================ */
.app-card {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    box-shadow: var(--shadow-sm);
    transition: var(--transition);
    gap: 16px;
    border: 1px solid transparent;
}

.app-card:hover {
    box-shadow: var(--shadow-md);
    border-color: rgba(108, 92, 231, 0.15);
    transform: translateY(-1px);
}

.app-info {
    display: flex;
    align-items: center;
    gap: 16px;
    flex: 1;
    min-width: 0;
}

/* App Icon */
.app-icon {
    width: 56px;
    height: 56px;
    border-radius: var(--radius-md);
    overflow: hidden;
    flex-shrink: 0;
    box-shadow: var(--shadow-sm);
}

.app-icon img {
    width: 100%;
    height: 100%;
    object-fit: cover;
}

.app-icon-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #dfe6e9, #b2bec3);
    color: #636e72;
    font-size: 20px;
    font-weight: 700;
}

.app-icon-blue {
    background: linear-gradient(135deg, #74b9ff, #0984e3);
    color: #fff;
}

/* App Details */
.app-details {
    flex: 1;
    min-width: 0;
}

.app-name-row {
    display: flex;
    align-items: center;
    gap: 10px;
    margin-bottom: 6px;
    flex-wrap: wrap;
}

.app-name {
    font-size: 16px;
    font-weight: 700;
    color: var(--text-primary);
}

/* Badge */
.badge {
    display: inline-flex;
    align-items: center;
    gap: 3px;
    padding: 3px 10px;
    border-radius: 20px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.badge-online {
    background: var(--green-bg);
    color: var(--green);
    border: 1px solid rgba(0, 184, 148, 0.2);
}

.badge-offline {
    background: var(--orange-bg);
    color: var(--orange);
    border: 1px solid rgba(225, 112, 85, 0.2);
}

.badge-delisted {
    background: var(--red-bg);
    color: var(--red);
    border: 1px solid rgba(214, 48, 49, 0.2);
}

/* App Meta */
.app-meta p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.6;
}

.app-meta strong {
    font-weight: 600;
    color: var(--text-primary);
}

.app-time {
    color: var(--text-muted) !important;
    font-size: 12px !important;
}

/* App Actions */
.app-actions {
    display: flex;
    gap: 8px;
    flex-shrink: 0;
}

/* ============================
   Buttons
   ============================ */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 8px 16px;
    border: none;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 13px;
    font-weight: 600;
    cursor: pointer;
    transition: var(--transition);
    white-space: nowrap;
}

.btn:active {
    transform: scale(0.96);
}

.btn-detail {
    background: var(--green-bg);
    color: var(--green);
}

.btn-detail:hover {
    background: var(--green);
    color: #fff;
    box-shadow: 0 3px 10px rgba(0, 184, 148, 0.3);
}

.btn-history {
    background: var(--blue-bg);
    color: var(--blue);
}

.btn-history:hover {
    background: var(--blue);
    color: #fff;
    box-shadow: 0 3px 10px rgba(9, 132, 227, 0.3);
}

.btn-delete {
    background: var(--red-bg);
    color: var(--red);
}

.btn-delete:hover {
    background: var(--red);
    color: #fff;
    box-shadow: 0 3px 10px rgba(214, 48, 49, 0.3);
}

.btn-sm {
    padding: 5px 12px;
    font-size: 12px;
}

/* ============================
   Add Form
   ============================ */
.add-form-container,
.email-container {
    background: var(--card-bg);
    border-radius: var(--radius-lg);
    padding: 32px;
    box-shadow: var(--shadow-md);
}

.form-title {
    font-size: 20px;
    font-weight: 700;
    margin-bottom: 24px;
    color: var(--text-primary);
}

.form-group {
    margin-bottom: 20px;
}

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.form-group input {
    width: 100%;
    padding: 12px 16px;
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    color: var(--text-primary);
    transition: var(--transition);
    background: #fafafa;
}

.form-group input:focus {
    outline: none;
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(108, 92, 231, 0.1);
}

.form-group input::placeholder {
    color: var(--text-muted);
}

.btn-submit {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    gap: 6px;
    width: 100%;
    padding: 14px 24px;
    border: none;
    border-radius: var(--radius-sm);
    background: linear-gradient(135deg, var(--primary), var(--primary-dark));
    color: #fff;
    font-family: inherit;
    font-size: 15px;
    font-weight: 700;
    cursor: pointer;
    transition: var(--transition);
}

.btn-submit:hover {
    transform: translateY(-1px);
    box-shadow: 0 6px 20px rgba(108, 92, 231, 0.35);
}

.btn-submit:active {
    transform: scale(0.98);
}

.btn-submit-sm {
    width: auto;
    padding: 12px 24px;
}

/* ============================
   Region Selector (Searchable)
   ============================ */
.region-selector {
    border: 2px solid var(--border);
    border-radius: var(--radius-sm);
    background: #fafafa;
    transition: var(--transition);
    padding: 8px 12px;
}

.region-selector:focus-within {
    border-color: var(--primary);
    background: #fff;
    box-shadow: 0 0 0 4px rgba(108, 92, 231, 0.1);
}

.region-selected-tags {
    display: flex;
    flex-wrap: wrap;
    gap: 6px;
    margin-bottom: 0;
}

.region-selected-tags:not(:empty) {
    margin-bottom: 8px;
}

.region-selected-tag {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 4px 10px;
    border-radius: 16px;
    font-size: 13px;
    font-weight: 600;
    background: rgba(108, 92, 231, 0.1);
    color: var(--primary);
    border: 1px solid rgba(108, 92, 231, 0.2);
    animation: fadeIn 0.2s ease;
}

.region-selected-tag .tag-remove {
    display: inline-flex;
    align-items: center;
    justify-content: center;
    width: 16px;
    height: 16px;
    border-radius: 50%;
    background: transparent;
    border: none;
    font-size: 14px;
    line-height: 1;
    cursor: pointer;
    color: var(--primary);
    transition: var(--transition);
    padding: 0;
    margin-left: 2px;
}

.region-selected-tag .tag-remove:hover {
    background: var(--primary);
    color: #fff;
}

.region-search-wrapper {
    position: relative;
}

.region-search-input {
    width: 100%;
    padding: 8px 4px;
    border: none;
    background: transparent;
    font-family: inherit;
    font-size: 14px;
    color: var(--text-primary);
    outline: none;
}

.region-search-input::placeholder {
    color: var(--text-muted);
}

.region-dropdown {
    display: none;
    position: absolute;
    top: calc(100% + 4px);
    left: -12px;
    right: -12px;
    max-height: 240px;
    overflow-y: auto;
    background: var(--card-bg);
    border: 1px solid var(--border);
    border-radius: var(--radius-sm);
    box-shadow: var(--shadow-lg);
    z-index: 100;
}

.region-dropdown.show {
    display: block;
}

.region-dropdown-item {
    display: flex;
    align-items: center;
    gap: 8px;
    padding: 10px 14px;
    cursor: pointer;
    transition: background 0.15s ease;
    font-size: 14px;
    color: var(--text-primary);
}

.region-dropdown-item:hover {
    background: rgba(108, 92, 231, 0.06);
}

.region-dropdown-item.selected {
    background: rgba(108, 92, 231, 0.1);
    color: var(--primary);
    font-weight: 600;
}

.region-dropdown-item .region-item-flag {
    font-size: 18px;
    flex-shrink: 0;
}

.region-dropdown-item .region-item-name {
    flex: 1;
}

.region-dropdown-item .region-item-code {
    font-size: 12px;
    color: var(--text-muted);
    font-weight: 500;
}

.region-dropdown-item .region-item-check {
    color: var(--primary);
    font-weight: 700;
}

.region-dropdown-empty {
    padding: 16px;
    text-align: center;
    color: var(--text-muted);
    font-size: 13px;
}

/* ============================
   Region Picker (legacy)
   ============================ */
.label-hint {
    font-size: 12px;
    font-weight: 400;
    color: var(--text-muted);
}

.region-picker {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    padding: 4px 0;
}

.region-checkbox {
    display: flex;
    align-items: center;
    gap: 6px;
    cursor: pointer;
    user-select: none;
}

.region-checkbox input[type="checkbox"] {
    display: none;
}

.region-checkbox-label {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 6px 14px;
    border-radius: 20px;
    font-size: 13px;
    font-weight: 500;
    background: #f0f2f5;
    border: 2px solid var(--border);
    color: var(--text-secondary);
    transition: var(--transition);
    cursor: pointer;
}

.region-checkbox input[type="checkbox"]:checked + .region-checkbox-label {
    background: rgba(108, 92, 231, 0.1);
    border-color: var(--primary);
    color: var(--primary);
    font-weight: 600;
}

.region-checkbox-label:hover {
    border-color: var(--primary-light);
    background: rgba(108, 92, 231, 0.05);
}

/* ============================
   Region Tags (App Card)
   ============================ */
.region-tags-row {
    display: flex;
    align-items: center;
    gap: 6px;
    flex-wrap: wrap;
    font-size: 13px;
    color: var(--text-secondary);
    margin-top: 2px;
}

.region-tags-row strong {
    font-weight: 600;
    color: var(--text-primary);
}

.region-tag {
    display: inline-flex;
    align-items: center;
    gap: 2px;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 12px;
    font-weight: 600;
    white-space: nowrap;
}

.region-tag-online {
    background: var(--green-bg);
    color: var(--green);
}

.region-tag-offline {
    background: var(--orange-bg);
    color: var(--orange);
}

/* ============================
   Email Management
   ============================ */
.email-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
    margin-bottom: 28px;
}

.email-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 14px 16px;
    background: #fafafa;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.email-address {
    flex: 1;
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
}

.email-status {
    font-size: 12px;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 20px;
}

.email-status.active {
    background: var(--green-bg);
    color: var(--green);
}

.email-input-row {
    display: flex;
    gap: 10px;
}

.email-input-row input {
    flex: 1;
}

/* ============================
   SMTP Config
   ============================ */
.smtp-hint {
    font-size: 13px;
    color: var(--text-muted);
    margin-bottom: 16px;
    line-height: 1.6;
}

.smtp-status {
    margin-bottom: 16px;
}

.smtp-configured {
    display: inline-block;
    padding: 6px 14px;
    background: var(--green-bg);
    color: var(--green);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

.smtp-not-configured {
    display: inline-block;
    padding: 6px 14px;
    background: var(--orange-bg);
    color: var(--orange);
    border-radius: 20px;
    font-size: 13px;
    font-weight: 600;
}

.smtp-btn-row {
    display: flex;
    gap: 10px;
}

.btn-test {
    background: linear-gradient(135deg, var(--blue), #0771c9) !important;
    flex: 0 0 auto;
}

/* ============================
   Empty State
   ============================ */
.empty-state {
    text-align: center;
    padding: 48px 20px;
    color: var(--text-muted);
}

.empty-state p {
    font-size: 16px;
    margin-bottom: 8px;
}

.empty-hint {
    font-size: 13px !important;
    color: var(--text-muted);
}

/* ============================
   Modal
   ============================ */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0, 0, 0, 0.5);
    backdrop-filter: blur(4px);
    z-index: 1000;
    align-items: center;
    justify-content: center;
    padding: 20px;
    animation: fadeIn 0.2s ease;
}

.modal-overlay.active {
    display: flex;
}

.modal {
    background: var(--card-bg);
    border-radius: var(--radius-xl);
    box-shadow: var(--shadow-lg);
    width: 100%;
    max-width: 560px;
    max-height: 80vh;
    overflow: hidden;
    display: flex;
    flex-direction: column;
    animation: modalSlideIn 0.3s ease;
}

@keyframes modalSlideIn {
    from {
        opacity: 0;
        transform: translateY(20px) scale(0.96);
    }

    to {
        opacity: 1;
        transform: translateY(0) scale(1);
    }
}

.modal-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 20px 24px;
    border-bottom: 1px solid var(--border);
}

.modal-title {
    font-size: 18px;
    font-weight: 700;
}

.modal-close {
    width: 32px;
    height: 32px;
    border: none;
    background: var(--bg);
    border-radius: 50%;
    font-size: 20px;
    cursor: pointer;
    display: flex;
    align-items: center;
    justify-content: center;
    color: var(--text-secondary);
    transition: var(--transition);
}

.modal-close:hover {
    background: var(--red-bg);
    color: var(--red);
}

.modal-body {
    padding: 24px;
    overflow-y: auto;
}

/* ============================
   Detail Card
   ============================ */
.detail-header {
    display: flex;
    align-items: center;
    gap: 16px;
    margin-bottom: 20px;
}

.detail-icon {
    width: 64px;
    height: 64px;
    border-radius: var(--radius-md);
    object-fit: cover;
    box-shadow: var(--shadow-sm);
}

.detail-icon-placeholder {
    display: flex;
    align-items: center;
    justify-content: center;
    background: linear-gradient(135deg, #dfe6e9, #b2bec3);
    font-size: 24px;
    font-weight: 700;
    color: #636e72;
}

.detail-name {
    font-size: 18px;
    font-weight: 700;
    margin-bottom: 6px;
}

.detail-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 12px;
}

.detail-item {
    display: flex;
    flex-direction: column;
    gap: 4px;
    padding: 10px 14px;
    background: #fafafa;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.detail-item strong {
    font-size: 11px;
    font-weight: 600;
    color: var(--text-muted);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.detail-item span {
    font-size: 14px;
    font-weight: 500;
    color: var(--text-primary);
    word-break: break-all;
}

.detail-desc {
    margin-top: 16px;
    padding: 14px;
    background: #fafafa;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.detail-desc strong {
    display: block;
    font-size: 13px;
    font-weight: 600;
    color: var(--text-primary);
    margin-bottom: 8px;
}

.detail-desc p {
    font-size: 13px;
    color: var(--text-secondary);
    line-height: 1.7;
    white-space: pre-wrap;
}

/* ============================
   History List
   ============================ */
.history-list {
    display: flex;
    flex-direction: column;
    gap: 10px;
}

.history-item {
    display: flex;
    align-items: center;
    gap: 12px;
    padding: 12px 14px;
    background: #fafafa;
    border-radius: var(--radius-sm);
    border: 1px solid var(--border);
}

.history-icon {
    font-size: 20px;
    flex-shrink: 0;
}

.history-info {
    flex: 1;
    display: flex;
    flex-direction: column;
    gap: 2px;
}

.history-label {
    font-size: 14px;
    font-weight: 600;
    color: var(--text-primary);
}

.history-detail {
    font-size: 13px;
    color: var(--text-secondary);
}

.history-time {
    font-size: 12px;
    color: var(--text-muted);
    white-space: nowrap;
}

/* ============================
   Toast
   ============================ */
.toast {
    position: fixed;
    bottom: -60px;
    left: 50%;
    transform: translateX(-50%);
    padding: 12px 24px;
    border-radius: var(--radius-sm);
    font-family: inherit;
    font-size: 14px;
    font-weight: 600;
    color: #fff;
    z-index: 2000;
    transition: bottom 0.3s ease;
    white-space: nowrap;
    box-shadow: var(--shadow-lg);
}

.toast.show {
    bottom: 32px;
}

.toast-success {
    background: var(--green);
}

.toast-error {
    background: var(--red);
}

.toast-info {
    background: var(--primary);
}

/* ============================
   Responsive
   ============================ */
@media (max-width: 768px) {
    .container {
        padding: 20px 12px 40px;
    }

    .header {
        padding: 28px 16px 22px;
    }

    .header-title {
        font-size: 22px;
    }

    .app-card {
        flex-direction: column;
        align-items: flex-start;
        padding: 16px;
    }

    .app-actions {
        width: 100%;
        justify-content: flex-end;
        padding-top: 12px;
        border-top: 1px solid var(--border);
    }

    .section-header {
        flex-direction: column;
        align-items: flex-start;
    }

    .tab-btn {
        font-size: 13px;
        padding: 14px 8px;
    }

    .detail-grid {
        grid-template-columns: 1fr;
    }

    .modal {
        max-height: 90vh;
    }
}

@media (max-width: 480px) {
    .header-title {
        font-size: 20px;
    }

    .status-bar {
        font-size: 12px;
    }

    .app-actions {
        flex-wrap: wrap;
    }

    .btn {
        padding: 7px 12px;
        font-size: 12px;
    }
}