/* ===== CSS Variables ===== */
:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --success: #16a34a;
    --success-light: #dcfce7;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-500: #6b7280;
    --gray-700: #374151;
    --gray-900: #111827;
    --white: #ffffff;
    --shadow-sm: 0 1px 2px rgba(0,0,0,0.05);
    --shadow-md: 0 4px 6px -1px rgba(0,0,0,0.1);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1);
    --radius: 8px;
    --radius-lg: 12px;
}

/* ===== Reset ===== */
* { margin: 0; padding: 0; box-sizing: border-box; }

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, 'Helvetica Neue', Arial, 'PingFang TC', 'Microsoft JhengHei', sans-serif;
    background: var(--gray-50);
    color: var(--gray-900);
    line-height: 1.5;
    min-height: 100vh;
}

/* ===== Topbar ===== */
.topbar {
    background: var(--white);
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 100;
    box-shadow: var(--shadow-sm);
}

.topbar-inner {
    max-width: 1200px;
    margin: 0 auto;
    padding: 0.75rem 1rem;
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 1rem;
}

.logo {
    font-size: 1.25rem;
    font-weight: 700;
    color: var(--primary);
    display: flex;
    align-items: center;
    gap: 0.5rem;
}

.logo i { font-size: 1.1rem; }

/* ===== Container ===== */
.container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 1.5rem 1rem;
}

/* ===== Buttons ===== */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 0.4rem;
    padding: 0.5rem 1rem;
    border: none;
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s ease;
    text-decoration: none;
}

.btn-primary {
    background: var(--primary);
    color: var(--white);
}
.btn-primary:hover { background: var(--primary-dark); }

.btn-ghost {
    background: transparent;
    color: var(--gray-700);
    border: 1px solid var(--gray-300);
}
.btn-ghost:hover { background: var(--gray-100); }

.btn-danger {
    background: var(--danger-light);
    color: var(--danger);
}
.btn-danger:hover { background: #fecaca; }

.btn-sm { padding: 0.25rem 0.6rem; font-size: 0.75rem; }

.btn-icon {
    padding: 0.35rem 0.6rem;
    font-size: 0.8rem;
    border-radius: 6px;
}

/* ===== Filter Panel ===== */
.filter-panel {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    margin-bottom: 1.25rem;
    box-shadow: var(--shadow-sm);
}

.filter-header {
    display: flex;
    align-items: center;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.filter-actions {
    display: flex;
    gap: 0.5rem;
}

/* ===== Star ===== */
.col-star {
    width: 30px;
    text-align: right;
    padding-right: 0 !important;
}

.star-btn {
    background: none;
    border: none;
    cursor: pointer;
    font-size: 1.2rem;
    color: #d1d5db;
    padding: 0.25rem 0.1rem;
    transition: color 0.2s, transform 0.2s;
    line-height: 1;
}

.star-btn:hover {
    color: #f59e0b;
    transform: scale(1.15);
}

.star-btn.starred {
    color: #f59e0b;
    text-shadow: 0 0 4px rgba(245, 158, 11, 0.4);
}

.filter-header h2 {
    font-size: 1rem;
    font-weight: 600;
    color: var(--gray-700);
    display: flex;
    align-items: center;
    gap: 0.4rem;
}

.filter-grid {
    display: grid;
    grid-template-columns: 1fr 2fr 1fr;
    gap: 1rem;
    align-items: start;
}

.filter-item label {
    display: block;
    font-size: 0.75rem;
    font-weight: 600;
    color: var(--gray-500);
    margin-bottom: 0.35rem;
    text-transform: uppercase;
    letter-spacing: 0.03em;
}

.filter-item input[type="text"],
.filter-item select {
    width: 100%;
    padding: 0.5rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.875rem;
    background: var(--white);
    transition: border-color 0.15s;
}

.filter-item input[type="text"]:focus,
.filter-item select:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.checkbox-group {
    display: flex;
    flex-wrap: wrap;
    gap: 0.5rem 1rem;
}

.checkbox {
    display: inline-flex;
    align-items: center;
    gap: 0.35rem;
    font-size: 0.85rem;
    color: var(--gray-700);
    cursor: pointer;
}

.checkbox input {
    accent-color: var(--primary);
    width: 15px;
    height: 15px;
    cursor: pointer;
}

/* ===== Stats ===== */
.stats-row {
    display: grid;
    grid-template-columns: 1fr;
    gap: 1rem;
    margin-bottom: 1.25rem;
}

.stat-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    display: flex;
    flex-direction: column;
    align-items: center;
    box-shadow: var(--shadow-sm);
}

.stat-num {
    font-size: 1.75rem;
    font-weight: 700;
    color: var(--primary);
}

.stat-label {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-top: 0.15rem;
}

/* ===== Table ===== */
.table-wrap {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    overflow-x: auto;
    box-shadow: var(--shadow-sm);
}

.data-table {
    width: 100%;
    border-collapse: collapse;
    min-width: 600px;
    table-layout: fixed;
}

.data-table th:nth-child(1) { width: 5%; }
.data-table th:nth-child(2) { width: 18%; }
.data-table th:nth-child(3) { width: 50%; }
.data-table th:nth-child(4) { width: 12%; }
.data-table th:nth-child(5) { width: 15%; }

.data-table td:nth-child(3) .service-badges {
    word-break: break-all;
}

.data-table thead th {
    background: var(--gray-50);
    padding: 0.75rem 1rem;
    text-align: left;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.03em;
    color: var(--gray-500);
    border-bottom: 1px solid var(--gray-200);
    white-space: nowrap;
}

.data-table tbody td {
    padding: 0.75rem 1rem;
    border-bottom: 1px solid var(--gray-100);
    font-size: 0.875rem;
    vertical-align: middle;
}

.data-table tbody tr:hover { background: var(--gray-50); }
.data-table tbody tr:last-child td { border-bottom: none; }

.company-cell {
    display: flex;
    flex-direction: column;
}

.company-name {
    font-weight: 600;
    color: var(--gray-900);
}

.company-domain {
    font-size: 0.75rem;
    color: var(--gray-500);
}

/* Service badges */
.service-badges {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 0.3rem;
}

.service-row {
    display: flex;
    align-items: center;
    gap: 0.3rem;
}

.service-edit-btn {
    background: none;
    border: none;
    cursor: pointer;
    color: var(--gray-500);
    font-size: 0.7rem;
    padding: 0.1rem 0.2rem;
    transition: color 0.2s;
}

.service-edit-btn:hover {
    color: var(--primary);
}

.service-extra {
    display: flex;
    flex-direction: column;
    gap: 0.1rem;
    margin-left: 0.25rem;
}

.service-price {
    font-size: 0.7rem;
    color: var(--success);
    font-weight: 600;
}

.service-details {
    font-size: 0.7rem;
    color: var(--gray-500);
}

/* ===== Context Menu ===== */
.context-menu {
    position: fixed;
    z-index: 1000;
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    box-shadow: var(--shadow-lg);
    min-width: 160px;
    padding: 0.25rem;
}

.context-menu-item {
    display: flex;
    align-items: center;
    gap: 0.5rem;
    width: 100%;
    padding: 0.5rem 0.75rem;
    background: none;
    border: none;
    border-radius: 6px;
    cursor: pointer;
    font-size: 0.85rem;
    color: var(--gray-700);
    text-align: left;
    transition: background 0.15s;
}

.context-menu-item:hover {
    background: var(--gray-100);
}

.badge {
    display: inline-flex;
    align-items: center;
    gap: 0.25rem;
    padding: 0.2rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 500;
    white-space: nowrap;
}

.service-link {
    text-decoration: none;
    cursor: pointer;
    transition: transform 0.15s ease, box-shadow 0.15s ease;
}

.service-link:hover {
    transform: translateY(-1px);
    box-shadow: 0 2px 4px rgba(0,0,0,0.1);
}

.tag-badges {
    display: flex;
    flex-wrap: wrap;
    gap: 0.25rem;
}

.tag-badge {
    display: inline-flex;
    align-items: center;
    padding: 0.15rem 0.5rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 500;
    background: var(--gray-100);
    color: var(--gray-700);
    border: 1px solid var(--gray-200);
}

.badge-domain { background: #ede9fe; color: #6d28d9; }
.badge-ssd_hosting { background: #dbeafe; color: #1d4ed8; }
.badge-wordpress { background: #e0e7ff; color: #4338ca; }
.badge-ssd_email { background: #cffafe; color: #0e7490; }
.badge-hosting { background: #dcfce7; color: #15803d; }
.badge-email { background: #fef3c7; color: #b45309; }

/* Status badge */
.status-badge {
    display: inline-flex;
    align-items: center;
    gap: 0.3rem;
    padding: 0.2rem 0.6rem;
    border-radius: 9999px;
    font-size: 0.7rem;
    font-weight: 500;
}

.status-active { background: var(--success-light); color: var(--success); }
.status-inactive { background: var(--gray-100); color: var(--gray-500); }

/* Action buttons */
.action-btns {
    display: flex;
    gap: 0.35rem;
}

/* ===== Card view (mobile) ===== */
.card-grid {
    display: none;
    grid-template-columns: 1fr;
    gap: 1rem;
}

.company-card {
    background: var(--white);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius-lg);
    padding: 1rem 1.25rem;
    box-shadow: var(--shadow-sm);
}

.card-header {
    display: flex;
    align-items: flex-start;
    justify-content: space-between;
    margin-bottom: 0.75rem;
}

.card-title {
    font-weight: 600;
    font-size: 1rem;
    color: var(--gray-900);
}

.card-domain {
    font-size: 0.8rem;
    color: var(--gray-500);
    margin-top: 0.1rem;
}

.card-services {
    margin-bottom: 0.75rem;
}

.card-remarks {
    display: flex;
    align-items: flex-start;
    gap: 0.4rem;
    font-size: 0.8rem;
    color: var(--gray-500);
    background: var(--gray-50);
    border-radius: var(--radius);
    padding: 0.5rem 0.6rem;
    margin-bottom: 0.75rem;
}

.card-remarks i {
    margin-top: 0.15rem;
    color: var(--warning);
}

.remarks-cell {
    max-width: 200px;
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
    color: var(--gray-500);
}

.card-actions {
    display: flex;
    gap: 0.5rem;
    border-top: 1px solid var(--gray-100);
    padding-top: 0.75rem;
}

/* ===== Empty state ===== */
.empty-state {
    text-align: center;
    padding: 3rem 1rem;
    color: var(--gray-500);
}

.empty-state i {
    font-size: 3rem;
    margin-bottom: 0.75rem;
    color: var(--gray-300);
}

/* ===== Modal ===== */
.modal-overlay {
    display: none;
    position: fixed;
    inset: 0;
    background: rgba(0,0,0,0.5);
    z-index: 200;
    align-items: center;
    justify-content: center;
    padding: 1rem;
}

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

.modal {
    background: var(--white);
    border-radius: var(--radius-lg);
    width: 100%;
    max-width: 480px;
    max-height: 90vh;
    overflow-y: auto;
    box-shadow: var(--shadow-lg);
}

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

.modal-header h3 {
    font-size: 1.1rem;
    font-weight: 600;
}

.btn-close {
    background: none;
    border: none;
    font-size: 1.1rem;
    color: var(--gray-500);
    cursor: pointer;
    padding: 0.25rem;
}
.btn-close:hover { color: var(--gray-900); }

.modal form { padding: 1.25rem; }

.form-group {
    margin-bottom: 1rem;
}

.form-group label {
    display: block;
    font-size: 0.8rem;
    font-weight: 600;
    color: var(--gray-700);
    margin-bottom: 0.35rem;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 0.55rem 0.75rem;
    border: 1px solid var(--gray-300);
    border-radius: var(--radius);
    font-size: 0.875rem;
    font-family: inherit;
    background: var(--white);
    transition: border-color 0.15s;
}

.form-group input:focus,
.form-group select:focus,
.form-group textarea:focus {
    outline: none;
    border-color: var(--primary);
    box-shadow: 0 0 0 3px var(--primary-light);
}

.modal-actions {
    display: flex;
    justify-content: flex-end;
    gap: 0.75rem;
    margin-top: 1.25rem;
}

/* ===== Toast ===== */
.toast {
    position: fixed;
    bottom: 1.5rem;
    left: 50%;
    transform: translateX(-50%) translateY(100px);
    background: var(--gray-900);
    color: var(--white);
    padding: 0.75rem 1.25rem;
    border-radius: var(--radius);
    font-size: 0.875rem;
    box-shadow: var(--shadow-lg);
    opacity: 0;
    transition: all 0.3s ease;
    z-index: 300;
    pointer-events: none;
}

.toast.show {
    opacity: 1;
    transform: translateX(-50%) translateY(0);
}

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

/* ===== Responsive ===== */
@media (max-width: 900px) {
    .filter-grid {
        grid-template-columns: 1fr 1fr;
    }
    .filter-item:last-child { grid-column: span 2; }
}

@media (max-width: 640px) {
    .topbar-inner { padding: 0.6rem 0.75rem; }
    .logo { font-size: 1.05rem; }
    .container { padding: 1rem 0.75rem; }

    .filter-grid { grid-template-columns: 1fr; }
    .filter-item:last-child { grid-column: auto; }

    .stats-row { grid-template-columns: repeat(3, 1fr); gap: 0.5rem; }
    .stat-card { padding: 0.75rem; }
    .stat-num { font-size: 1.4rem; }

    /* Hide table, show cards on mobile */
    .table-wrap { display: none; }
    .card-grid { display: grid; }

    .btn { padding: 0.45rem 0.8rem; font-size: 0.8rem; }
    .btn-sm { padding: 0.2rem 0.5rem; font-size: 0.7rem; }
}

@media (min-width: 641px) {
    .card-grid { display: none; }
    .table-wrap { display: block; }
}
