:root {
    --primary: #4f46e5;
    --primary-hover: #4338ca;
    --primary-light: #eef2ff;
    --bg: #f3f4f6;
    --card-bg: #ffffff;
    --text: #111827;
    --text-secondary: #6b7280;
    --text-muted: #9ca3af;
    --border: #e5e7eb;
    --success: #10b981;
    --error: #ef4444;
    --warning: #f59e0b;
    --info: #3b82f6;
    --radius: 12px;
    --shadow: 0 4px 6px -1px rgba(0,0,0,0.1), 0 2px 4px -1px rgba(0,0,0,0.06);
    --shadow-lg: 0 10px 15px -3px rgba(0,0,0,0.1), 0 4px 6px -2px rgba(0,0,0,0.05);
}

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

body {
    font-family: 'Inter', -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, Helvetica, Arial, sans-serif;
    background-color: var(--bg);
    color: var(--text);
    min-height: 100vh;
}

.hidden { display: none !important; }

/* Login Screen */
.login-screen {
    display: flex;
    align-items: center;
    justify-content: center;
    min-height: 100vh;
    background: linear-gradient(135deg, #4f46e5 0%, #7c3aed 100%);
}

.login-card {
    background: white;
    padding: 48px;
    border-radius: 16px;
    text-align: center;
    box-shadow: 0 25px 50px -12px rgba(0,0,0,0.25);
    max-width: 400px;
    width: 90%;
}

.login-card h1 {
    font-size: 2rem;
    font-weight: 800;
    background: linear-gradient(135deg, #4f46e5, #7c3aed);
    -webkit-background-clip: text;
    -webkit-text-fill-color: transparent;
    margin-bottom: 8px;
}

.login-card p {
    color: var(--text-secondary);
    margin-bottom: 24px;
    font-size: 0.95rem;
}

/* Buttons */
.btn {
    border: none;
    padding: 10px 20px;
    border-radius: 8px;
    font-weight: 500;
    cursor: pointer;
    font-size: 0.9rem;
    transition: all 0.15s ease;
}

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

.btn-outline {
    background: white;
    color: var(--primary);
    border: 1.5px solid var(--primary);
}
.btn-outline:hover { background: var(--primary-light); }

.btn-sm { padding: 6px 14px; font-size: 0.8rem; }

.link-btn {
    background: none;
    border: none;
    color: var(--text-secondary);
    font-size: 0.8rem;
    cursor: pointer;
    padding: 0;
}
.link-btn:hover { color: var(--error); text-decoration: underline; }

/* App Layout */
.app-container {
    max-width: 1200px;
    margin: 0 auto;
    padding: 20px 24px 60px;
}

/* Top Bar */
.top-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding-bottom: 20px;
    border-bottom: 2px solid var(--border);
    margin-bottom: 20px;
}

.top-bar h1 {
    font-size: 1.6rem;
    font-weight: 800;
    color: var(--text);
}
.top-bar h1 span { color: var(--primary); }

.user-profile { display: flex; align-items: center; gap: 10px; }
.avatar { width: 36px; height: 36px; border-radius: 50%; border: 2px solid white; box-shadow: 0 2px 4px rgba(0,0,0,0.1); }
.user-details { display: flex; flex-direction: column; align-items: flex-end; }
.user-details .name { font-weight: 600; font-size: 0.85rem; }

/* Breadcrumb */
.breadcrumb {
    display: flex;
    align-items: center;
    gap: 4px;
    padding: 12px 0;
    font-size: 0.85rem;
    flex-wrap: wrap;
}

.crumb {
    color: var(--primary);
    cursor: pointer;
    font-weight: 500;
    padding: 4px 8px;
    border-radius: 6px;
    transition: background 0.15s;
}
.crumb:hover { background: var(--primary-light); }
.crumb.active { color: var(--text); cursor: default; font-weight: 600; }
.crumb.active:hover { background: none; }

.crumb-sep {
    color: var(--text-muted);
    font-size: 0.75rem;
    user-select: none;
}

/* Cards Grid */
.cards-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(280px, 1fr));
    gap: 20px;
    margin-top: 16px;
}

.nav-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    padding: 24px;
    box-shadow: var(--shadow);
    cursor: pointer;
    transition: all 0.2s ease;
    border: 2px solid transparent;
    position: relative;
    overflow: hidden;
}

.nav-card:hover {
    transform: translateY(-3px);
    box-shadow: var(--shadow-lg);
    border-color: var(--primary);
}

.nav-card .card-icon {
    font-size: 2rem;
    margin-bottom: 12px;
    display: block;
}

.nav-card .card-title {
    font-size: 1.1rem;
    font-weight: 700;
    color: var(--text);
    margin-bottom: 4px;
}

.nav-card .card-subtitle {
    font-size: 0.85rem;
    color: var(--text-secondary);
}

.nav-card .card-badge {
    position: absolute;
    top: 16px;
    right: 16px;
    background: var(--primary-light);
    color: var(--primary);
    font-size: 0.75rem;
    font-weight: 600;
    padding: 3px 10px;
    border-radius: 99px;
}

/* Section Header */
.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 20px;
}

.section-header h2 {
    font-size: 1.3rem;
    font-weight: 700;
}

/* Data Table */
.table-wrap {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin-top: 16px;
}

.table-wrap table {
    width: 100%;
    border-collapse: collapse;
    font-size: 0.85rem;
}

.table-wrap th {
    background: #f9fafb;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 0.7rem;
    letter-spacing: 0.05em;
    padding: 12px 16px;
    text-align: left;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}

.table-wrap td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    line-height: 1.5;
    max-width: 400px;
    word-break: break-word;
}

.table-wrap tr:last-child td { border-bottom: none; }
.table-wrap tr:hover td { background: #f9fafb; }

.table-wrap td.clickable {
    color: var(--primary);
    cursor: pointer;
    font-weight: 500;
}
.table-wrap td.clickable:hover { text-decoration: underline; }

/* Detail Cards */
.detail-grid {
    display: grid;
    grid-template-columns: repeat(auto-fill, minmax(260px, 1fr));
    gap: 16px;
    margin-top: 16px;
}

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

.detail-card .label {
    font-size: 0.7rem;
    font-weight: 600;
    color: var(--text-secondary);
    text-transform: uppercase;
    letter-spacing: 0.05em;
    margin-bottom: 4px;
}

.detail-card .value {
    font-size: 0.95rem;
    font-weight: 500;
    color: var(--text);
    word-break: break-word;
    white-space: pre-wrap;
}

/* Info Banner */
.info-banner {
    background: var(--primary-light);
    border: 1px solid #c7d2fe;
    border-radius: var(--radius);
    padding: 16px 20px;
    margin-bottom: 20px;
    display: flex;
    align-items: center;
    gap: 12px;
    font-size: 0.9rem;
    color: var(--primary);
}

/* Chip List (for linked items) */
.chip-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin-top: 12px;
}

.chip {
    background: var(--primary-light);
    color: var(--primary);
    padding: 6px 14px;
    border-radius: 99px;
    font-size: 0.8rem;
    font-weight: 500;
    cursor: pointer;
    transition: all 0.15s;
    border: 1.5px solid transparent;
}
.chip:hover {
    border-color: var(--primary);
    transform: translateY(-1px);
}

/* Status badges */
.badge {
    display: inline-block;
    padding: 2px 10px;
    border-radius: 99px;
    font-size: 0.7rem;
    font-weight: 600;
    text-transform: uppercase;
}
.badge-success { background: #d1fae5; color: #065f46; }
.badge-warning { background: #fef3c7; color: #92400e; }
.badge-error { background: #fee2e2; color: #991b1b; }
.badge-info { background: #dbeafe; color: #1e40af; }

/* Empty state */
.empty-state {
    text-align: center;
    color: var(--text-secondary);
    padding: 40px 20px;
    font-size: 0.95rem;
}

.status-message { margin-top: 10px; font-size: 0.9rem; }
.status-message.error { color: var(--error); }
.status-message.success { color: var(--success); }

/* Loader */
.loader {
    border: 3px solid var(--bg);
    border-top: 3px solid var(--primary);
    border-radius: 50%;
    width: 24px;
    height: 24px;
    animation: spin 0.8s linear infinite;
    display: inline-block;
    vertical-align: middle;
    margin-right: 8px;
}
@keyframes spin { to { transform: rotate(360deg); } }

/* Responsive */
@media (max-width: 768px) {
    .app-container { padding: 12px 16px 40px; }
    .cards-grid { grid-template-columns: 1fr; }
    .detail-grid { grid-template-columns: 1fr; }
    .top-bar h1 { font-size: 1.3rem; }
    .table-wrap { overflow-x: auto; }
}

/* Company/Location child cards */
.child-section {
    margin-top: 24px;
    padding-top: 20px;
    border-top: 2px dashed var(--border);
}

.child-section h3 {
    font-size: 1rem;
    font-weight: 600;
    margin-bottom: 12px;
    color: var(--text-secondary);
}

/* ── Site Hardware card & table ─────────────────────────────── */
.hw-card {
    background: var(--card-bg);
    border-radius: var(--radius);
    box-shadow: var(--shadow);
    overflow: hidden;
    margin: 16px 0 28px;
}
.hw-card-head {
    display: flex;
    align-items: center;
    justify-content: space-between;
    flex-wrap: wrap;
    gap: 10px;
    padding: 16px 20px;
    background: linear-gradient(135deg, var(--primary-light) 0%, #ffffff 60%);
    border-bottom: 1px solid var(--border);
}
.hw-card-head h3 { font-size: 1.02rem; color: var(--text); }
.hw-card-head .hw-sub { font-size: 0.78rem; color: var(--text-secondary); margin-top: 2px; font-weight: 400; }
.hw-actions { display: flex; align-items: center; gap: 8px; }
.hw-btn {
    border: none;
    border-radius: 8px;
    padding: 8px 18px;
    font-size: 0.84rem;
    font-weight: 600;
    cursor: pointer;
    transition: all 0.15s;
}
.hw-btn-edit { background: var(--primary-light); color: var(--primary); border: 1px solid #c7d2fe; }
.hw-btn-edit:hover { background: var(--primary); color: #fff; }
.hw-btn-save { background: var(--success); color: #fff; }
.hw-btn-save:hover { filter: brightness(1.08); }
.hw-btn-save:disabled { opacity: 0.6; cursor: default; }
.hw-btn-cancel { background: #f3f4f6; color: var(--text-secondary); }
.hw-btn-cancel:hover { background: #e5e7eb; }
.hw-status-msg { font-size: 0.8rem; font-weight: 500; }
.hw-status-msg.ok { color: var(--success); }
.hw-status-msg.err { color: var(--error); }

.hw-scroll { overflow-x: auto; }
table.hw-table {
    width: 100%;
    border-collapse: separate;
    border-spacing: 0;
    font-size: 0.85rem;
    min-width: 640px;
}
.hw-table thead th {
    background: #f8fafc;
    color: var(--text-secondary);
    text-transform: uppercase;
    font-size: 0.7rem;
    font-weight: 700;
    letter-spacing: 0.06em;
    padding: 12px 16px;
    text-align: left;
    border-bottom: 2px solid var(--border);
    white-space: nowrap;
}
.hw-table td {
    padding: 12px 16px;
    border-bottom: 1px solid var(--border);
    vertical-align: top;
    line-height: 1.55;
    color: var(--text);
    max-width: 420px;
    word-break: break-word;
}
.hw-table tbody tr:nth-child(even) td { background: #fafbff; }
.hw-table tbody tr:hover td { background: var(--primary-light); }
.hw-table tbody tr:last-child td { border-bottom: none; }
.hw-table td.hw-field {
    font-weight: 600;
    white-space: nowrap;
    color: #374151;
    background: #f8fafc;
    border-right: 1px solid var(--border);
    position: sticky;
    left: 0;
    z-index: 1;
}
.hw-table tbody tr:nth-child(even) td.hw-field,
.hw-table tbody tr:hover td.hw-field { background: #f1f5f9; }
.hw-badge-na {
    display: inline-block;
    background: #f3f4f6;
    color: var(--text-muted);
    font-size: 0.72rem;
    font-weight: 600;
    padding: 2px 10px;
    border-radius: 999px;
}
.hw-empty { color: var(--text-muted); }
.hw-input {
    width: 100%;
    min-width: 190px;
    min-height: 58px;
    border: 1px solid var(--border);
    border-radius: 8px;
    padding: 8px 10px;
    font: inherit;
    font-size: 0.83rem;
    line-height: 1.45;
    resize: vertical;
    background: #fff;
}
.hw-input:focus { outline: none; border-color: var(--primary); box-shadow: 0 0 0 3px rgba(79, 70, 229, 0.12); }
input.hw-input-site {
    min-height: auto;
    font-weight: 600;
    padding: 6px 10px;
}

.hw-del {
    flex: none;
    width: 22px;
    height: 22px;
    border: none;
    border-radius: 6px;
    background: #fee2e2;
    color: var(--error);
    font-size: 0.7rem;
    font-weight: 700;
    cursor: pointer;
    line-height: 1;
    transition: all 0.15s;
}
.hw-del:hover { background: var(--error); color: #fff; }
