/* =============================================
   STEMLaunchPad — Main Stylesheet
   ============================================= */

:root {
    --primary: #2563eb;
    --primary-dark: #1d4ed8;
    --primary-light: #dbeafe;
    --secondary: #059669;
    --secondary-light: #d1fae5;
    --danger: #dc2626;
    --danger-light: #fee2e2;
    --warning: #d97706;
    --warning-light: #fef3c7;
    --gray-50: #f9fafb;
    --gray-100: #f3f4f6;
    --gray-200: #e5e7eb;
    --gray-300: #d1d5db;
    --gray-400: #9ca3af;
    --gray-500: #6b7280;
    --gray-600: #4b5563;
    --gray-700: #374151;
    --gray-800: #1f2937;
    --gray-900: #111827;
    --sidebar-width: 250px;
    --header-height: 60px;
    --radius: 14px;
    --shadow: 0 12px 30px rgba(15, 23, 42, 0.06), 0 1px 2px rgba(15, 23, 42, 0.05);
    --shadow-lg: 0 24px 50px rgba(15, 23, 42, 0.16), 0 6px 16px rgba(15, 23, 42, 0.08);
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    background:
        radial-gradient(circle at top left, #e0ecff 0, transparent 36%),
        linear-gradient(180deg, #f8fafc 0%, #eef2f7 45%, #f9fafb 100%);
    color: var(--gray-800);
    line-height: 1.6;
}

a { color: var(--primary); text-decoration: none; }
a:hover { text-decoration: underline; }

/* Login Page */
.login-page {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #1e3a5f 0%, #2563eb 100%);
}

.login-container { width: 100%; max-width: 400px; padding: 20px; }

.login-card {
    background: white;
    border-radius: var(--radius);
    padding: 40px;
    box-shadow: var(--shadow-lg);
}

.login-header { text-align: center; margin-bottom: 30px; }
.login-header h1 { font-size: 28px; color: var(--primary); }
.login-header p { color: var(--gray-500); font-size: 14px; margin-top: 4px; }

.login-footer { text-align: center; margin-top: 20px; color: var(--gray-400); }

/* Layout */
.layout { display: flex; min-height: 100vh; }

.sidebar {
    width: var(--sidebar-width);
    background: linear-gradient(180deg, #0f172a 0%, #111827 50%, #0b1220 100%);
    color: white;
    position: fixed;
    top: 0;
    left: 0;
    bottom: 0;
    overflow-y: auto;
    z-index: 100;
}

.sidebar-header {
    padding: 20px;
    border-bottom: 1px solid var(--gray-700);
}

.sidebar-header h2 { font-size: 18px; color: white; }
.sidebar-header small { color: var(--gray-400); font-size: 12px; }

.sidebar-nav { padding: 10px 0; }

.sidebar-nav a {
    display: flex;
    align-items: center;
    padding: 12px 20px;
    color: var(--gray-300);
    font-size: 14px;
    transition: all 0.2s;
    text-decoration: none;
    gap: 10px;
    border-radius: 12px;
    margin: 2px 10px;
}

.sidebar-nav a:hover {
    background: var(--gray-800);
    color: white;
    text-decoration: none;
}

.sidebar-nav a.active {
    background: linear-gradient(90deg, #2563eb 0%, #1d4ed8 100%);
    color: white;
    box-shadow: 0 10px 20px rgba(37, 99, 235, 0.24);
}

.sidebar-nav .nav-icon {
    width: 20px;
    text-align: center;
    font-size: 16px;
}

.sidebar-footer {
    padding: 15px 20px;
    border-top: 1px solid var(--gray-700);
    position: absolute;
    bottom: 0;
    width: 100%;
}

.sidebar-footer a {
    color: var(--gray-400);
    font-size: 13px;
}

.main-content {
    margin-left: var(--sidebar-width);
    flex: 1;
    min-height: 100vh;
}

.top-bar {
    background: rgba(255, 255, 255, 0.9);
    backdrop-filter: blur(10px);
    height: var(--header-height);
    display: flex;
    align-items: center;
    justify-content: space-between;
    padding: 0 30px;
    border-bottom: 1px solid var(--gray-200);
    position: sticky;
    top: 0;
    z-index: 50;
}

.top-bar h1 { font-size: 20px; font-weight: 600; }

.page-content { padding: 30px; }

/* Cards */
.card {
    background: rgba(255, 255, 255, 0.98);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    border: 1px solid rgba(226, 232, 240, 0.9);
    margin-bottom: 20px;
}

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

.card-header h2 { font-size: 16px; font-weight: 600; }

.card-body { padding: 20px; }

/* Stat Cards */
.stats-grid {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(200px, 1fr));
    gap: 20px;
    margin-bottom: 30px;
}

.stat-card {
    background: white;
    border-radius: var(--radius);
    padding: 20px;
    box-shadow: var(--shadow);
}

.stat-card .stat-label {
    font-size: 13px;
    color: var(--gray-500);
    text-transform: uppercase;
    letter-spacing: 0.5px;
}

.stat-card .stat-value {
    font-size: 32px;
    font-weight: 700;
    margin-top: 4px;
    color: var(--gray-900);
}

.stat-card .stat-sub {
    font-size: 13px;
    color: var(--gray-400);
    margin-top: 4px;
}

.stat-card.primary { border-left: 4px solid var(--primary); }
.stat-card.success { border-left: 4px solid var(--secondary); }
.stat-card.warning { border-left: 4px solid var(--warning); }
.stat-card.danger { border-left: 4px solid var(--danger); }

/* Forms */
.form-group { margin-bottom: 16px; }

.form-group label {
    display: block;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-700);
    margin-bottom: 4px;
}

.form-group input,
.form-group select,
.form-group textarea {
    width: 100%;
    padding: 10px 12px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    transition: border-color 0.2s;
    font-family: inherit;
}

.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);
}

.form-group textarea { min-height: 100px; resize: vertical; }

.form-row {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(250px, 1fr));
    gap: 16px;
}

.form-group .help-text {
    font-size: 12px;
    color: var(--gray-400);
    margin-top: 4px;
}

/* Buttons */
.btn {
    display: inline-flex;
    align-items: center;
    gap: 6px;
    padding: 9px 16px;
    border: none;
    border-radius: 10px;
    font-size: 14px;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.2s;
    text-decoration: none;
    line-height: 1.4;
}

.btn:hover { text-decoration: none; }

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

.btn-success { background: var(--secondary); color: white; }
.btn-success:hover { background: #047857; }

.btn-danger { background: var(--danger); color: white; }
.btn-danger:hover { background: #b91c1c; }

.btn-warning { background: var(--warning); color: white; }
.btn-warning:hover { background: #b45309; }

.btn-secondary { background: var(--gray-200); color: var(--gray-700); }
.btn-secondary:hover { background: var(--gray-300); }

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

.btn-full { width: 100%; justify-content: center; }

.btn-group { display: flex; gap: 8px; flex-wrap: wrap; }

.control-grid {
    display: grid;
    grid-template-columns: minmax(280px, 1.05fr) minmax(320px, 1fr) minmax(320px, 1fr);
    gap: 20px;
    align-items: start;
}

.control-panel {
    border: 1px solid var(--gray-200);
    border-radius: 18px;
    padding: 20px;
    background: linear-gradient(180deg, #ffffff 0%, #fbfdff 100%);
    box-shadow: 0 8px 24px rgba(15, 23, 42, 0.06);
    min-height: 100%;
}

.control-panel-header {
    display: flex;
    flex-direction: column;
    gap: 4px;
    margin-bottom: 16px;
    padding-bottom: 12px;
    border-bottom: 1px solid var(--gray-200);
}

.control-panel-header h3 {
    font-size: 16px;
    font-weight: 600;
    color: var(--gray-900);
    letter-spacing: -0.01em;
}

.action-row,
.delivery-row {
    display: flex;
    align-items: center;
    justify-content: space-between;
    gap: 16px;
    padding: 16px 0;
    border-top: 1px solid var(--gray-200);
}

.action-row:first-of-type,
.delivery-row:first-of-type {
    border-top: none;
    padding-top: 0;
}

.action-row:last-of-type,
.delivery-row:last-of-type {
    padding-bottom: 0;
}

.action-row strong,
.delivery-row strong {
    display: block;
    margin-bottom: 2px;
}

.action-row > div:first-child,
.delivery-row > div:first-child {
    flex: 1;
    min-width: 0;
}

.action-row .btn-group,
.delivery-row .btn-group {
    justify-content: flex-end;
}

.control-panel code {
    background: var(--gray-100);
    border: 1px solid var(--gray-200);
    border-radius: 4px;
    padding: 1px 5px;
    font-size: 12px;
    color: var(--gray-700);
}

.workflow-guide {
    display: grid;
    grid-template-columns: repeat(auto-fit, minmax(220px, 1fr));
    gap: 16px;
}

.workflow-step {
    display: flex;
    gap: 12px;
    align-items: flex-start;
    padding: 14px;
    background: linear-gradient(180deg, #f8fafc 0%, #eef2ff 100%);
    border: 1px solid var(--gray-200);
    border-radius: var(--radius);
}

.workflow-number {
    width: 28px;
    height: 28px;
    flex: 0 0 28px;
    border-radius: 999px;
    background: var(--primary);
    color: white;
    display: inline-flex;
    align-items: center;
    justify-content: center;
    font-size: 13px;
    font-weight: 700;
}

.workflow-note {
    margin-top: 16px;
    padding: 12px 14px;
    background: var(--primary-light);
    border: 1px solid #bfdbfe;
    border-radius: var(--radius);
    color: #1e3a8a;
    font-size: 14px;
}

.workflow-inline-help {
    margin-top: 14px;
    padding-top: 14px;
    border-top: 1px dashed var(--gray-300);
    color: var(--gray-600);
    font-size: 13px;
}

.batch-send-control {
    display: inline-flex;
    align-items: center;
    gap: 8px;
    background: var(--gray-50);
    border: 1px solid var(--gray-200);
    border-radius: 8px;
    padding: 6px 10px;
}

.batch-send-control input {
    width: 88px;
    padding: 6px 8px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
}

/* Tables */
.data-table {
    width: 100%;
    border-collapse: collapse;
}

.data-table th {
    text-align: left;
    padding: 12px 16px;
    font-size: 12px;
    font-weight: 600;
    text-transform: uppercase;
    letter-spacing: 0.5px;
    color: var(--gray-500);
    background: var(--gray-50);
    border-bottom: 2px solid var(--gray-200);
}

.data-table td {
    padding: 12px 16px;
    font-size: 14px;
    border-bottom: 1px solid var(--gray-100);
    vertical-align: middle;
}

.data-table tbody tr {
    transition: background 0.2s ease, transform 0.2s ease;
}

.data-table tr:hover {
    background: #f8fafc;
}

.data-table .actions { white-space: nowrap; }

/* Badges */
.badge {
    display: inline-block;
    padding: 4px 11px;
    border-radius: 50px;
    font-size: 12px;
    font-weight: 500;
}

.badge-primary { background: var(--primary-light); color: var(--primary); }
.badge-success { background: var(--secondary-light); color: var(--secondary); }
.badge-warning { background: var(--warning-light); color: var(--warning); }
.badge-danger { background: var(--danger-light); color: var(--danger); }
.badge-gray { background: var(--gray-200); color: var(--gray-600); }

/* Alerts */
.alert {
    padding: 12px 16px;
    border-radius: 6px;
    margin-bottom: 16px;
    font-size: 14px;
}

.alert-success { background: var(--secondary-light); color: #065f46; border: 1px solid #a7f3d0; }
.alert-error { background: var(--danger-light); color: #991b1b; border: 1px solid #fecaca; }
.alert-warning { background: var(--warning-light); color: #92400e; border: 1px solid #fde68a; }
.alert-info { background: var(--primary-light); color: #1e40af; border: 1px solid #bfdbfe; }

/* Modal */
.modal-overlay {
    display: none;
    position: fixed;
    top: 0;
    left: 0;
    right: 0;
    bottom: 0;
    background: rgba(0,0,0,0.5);
    z-index: 1000;
    align-items: center;
    justify-content: center;
}

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

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

.modal-lg {
    max-width: 920px;
}

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

.modal-header h3 { font-size: 16px; }

.modal-close {
    background: none;
    border: none;
    font-size: 20px;
    cursor: pointer;
    color: var(--gray-400);
    padding: 4px;
}

.modal-body { padding: 20px; }

.modal-footer {
    padding: 16px 20px;
    border-top: 1px solid var(--gray-200);
    display: flex;
    justify-content: flex-end;
    gap: 8px;
}

/* Preview */
.preview-box {
    background: linear-gradient(180deg, #f8fafc 0%, #ffffff 100%);
    border: 1px solid #e2e8f0;
    border-radius: var(--radius);
    padding: 20px;
    margin: 10px 0;
}

.preview-box pre {
    white-space: pre-wrap;
    word-wrap: break-word;
    font-size: 13px;
}

/* Empty State */
.empty-state {
    text-align: center;
    padding: 60px 20px;
    color: var(--gray-400);
}

.empty-state h3 { color: var(--gray-500); margin-bottom: 8px; }

/* Loading */
.loading {
    display: inline-block;
    width: 18px;
    height: 18px;
    border: 2px solid var(--gray-300);
    border-top-color: var(--primary);
    border-radius: 50%;
    animation: spin 0.6s linear infinite;
}

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

.loading-overlay {
    position: absolute;
    inset: 0;
    background: rgba(255,255,255,0.8);
    display: flex;
    align-items: center;
    justify-content: center;
    z-index: 10;
}

/* Tabs */
.tabs {
    display: flex;
    border-bottom: 2px solid var(--gray-200);
    margin-bottom: 20px;
    gap: 0;
}

.tab {
    padding: 10px 20px;
    font-size: 14px;
    font-weight: 500;
    color: var(--gray-500);
    cursor: pointer;
    border-bottom: 2px solid transparent;
    margin-bottom: -2px;
    transition: all 0.2s;
    background: none;
    border-top: none;
    border-left: none;
    border-right: none;
}

.tab:hover { color: var(--gray-700); }
.tab.active { color: var(--primary); border-bottom-color: var(--primary); }

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

/* Pagination */
.pagination {
    display: flex;
    gap: 4px;
    justify-content: center;
    margin-top: 20px;
}

.pagination a, .pagination span {
    padding: 8px 14px;
    border: 1px solid var(--gray-300);
    border-radius: 6px;
    font-size: 14px;
    color: var(--gray-600);
}

.pagination a:hover { background: var(--gray-100); text-decoration: none; }
.pagination .active { background: var(--primary); color: white; border-color: var(--primary); }

/* JSON viewer */
.json-display {
    background: var(--gray-900);
    color: #a5f3fc;
    padding: 16px;
    border-radius: 6px;
    font-family: 'SF Mono', Monaco, monospace;
    font-size: 13px;
    overflow-x: auto;
    white-space: pre-wrap;
    word-wrap: break-word;
}

/* Responsive */
@media (max-width: 768px) {
    .sidebar { display: none; }
    .main-content { margin-left: 0; }
    .stats-grid { grid-template-columns: 1fr 1fr; }
    .form-row { grid-template-columns: 1fr; }
    .top-bar { padding: 0 15px; }
    .page-content { padding: 15px; }
    .action-row, .delivery-row { flex-direction: column; align-items: flex-start; }
    .control-grid { grid-template-columns: 1fr; }
}

@media (max-width: 1180px) and (min-width: 769px) {
    .control-grid {
        grid-template-columns: 1fr 1fr;
    }

    .control-panel:first-child {
        grid-column: 1 / -1;
    }
}

/* Utility */
.text-muted { color: var(--gray-500); }
.text-sm { font-size: 13px; }
.text-right { text-align: right; }
.mb-0 { margin-bottom: 0; }
.mb-2 { margin-bottom: 8px; }
.mb-4 { margin-bottom: 16px; }
.mt-2 { margin-top: 8px; }
.mt-4 { margin-top: 16px; }
.flex { display: flex; }
.items-center { align-items: center; }
.justify-between { justify-content: space-between; }
.gap-2 { gap: 8px; }
.gap-4 { gap: 16px; }
.truncate { overflow: hidden; text-overflow: ellipsis; white-space: nowrap; max-width: 200px; }
