:root {
    --border: #e5e7eb;
    --surface: #ffffff;
    --bg: #f5f5f5;
    --text: #333333;
    --muted: #6b7280;
    --primary: #2563eb;
    --danger: #dc2626;
}

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

body {
    font-family: -apple-system, BlinkMacSystemFont, 'Segoe UI', Roboto, sans-serif;
    line-height: 1.6;
    color: var(--text);
    max-width: 960px;
    margin: 0 auto;
    padding: 20px;
    background: var(--bg);
}

nav {
    display: flex;
    gap: 15px;
    padding: 10px 0;
    margin-bottom: 20px;
    border-bottom: 1px solid #ddd;
}

nav a {
    color: #2563eb;
    text-decoration: none;
    font-weight: 500;
}

nav a:hover {
    text-decoration: underline;
}

h1 { margin-bottom: 15px; color: #1e293b; }
h2 { margin: 20px 0 10px; color: #475569; }

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

label {
    display: block;
    margin-bottom: 4px;
    font-weight: 500;
    color: #475569;
}

input[type="text"],
input[type="number"],
select {
    padding: 8px 12px;
    border: 1px solid #d1d5db;
    border-radius: 4px;
    font-size: 14px;
    width: 100%;
    max-width: 300px;
}

button {
    padding: 10px 20px;
    background: #2563eb;
    color: white;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    margin-top: 10px;
}

button:hover {
    background: #1d4ed8;
}

button[type="button"] {
    background: #6b7280;
    padding: 5px 10px;
    font-size: 12px;
}

button[type="button"]:hover {
    background: #4b5563;
}

.subsystem-entry {
    background: white;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 10px;
    border: 1px solid #e5e7eb;
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.subsystem-entry .form-group {
    margin-bottom: 0;
}

.component-entry {
    background: white;
    padding: 15px;
    border-radius: 6px;
    margin-bottom: 10px;
    border: 1px solid #e5e7eb;
    display: flex;
    gap: 15px;
    flex-wrap: wrap;
    align-items: flex-end;
}

.component-entry .form-group {
    margin-bottom: 0;
}

.element-row {
    display: flex;
    gap: 10px;
    align-items: center;
    margin-bottom: 8px;
}

.element-row input {
    max-width: 200px;
}

.coupling-matrix {
    width: 100%;
    border-collapse: collapse;
    margin: 20px 0;
    background: white;
    border-radius: 6px;
    overflow: hidden;
}

.coupling-matrix th,
.coupling-matrix td {
    border: 1px solid #e5e7eb;
    padding: 8px;
    text-align: center;
    font-size: 13px;
}

.coupling-matrix th {
    background: #f8fafc;
    font-weight: 600;
    color: #475569;
}

.coupling-cell {
    text-align: left;
}

.coupling-field {
    margin: 2px 0;
    display: flex;
    align-items: center;
    gap: 4px;
    font-size: 11px;
}

.coupling-label {
    color: #6b7280;
    max-width: 180px;
    overflow: hidden;
    text-overflow: ellipsis;
    white-space: nowrap;
}

.coupling-field input {
    width: 50px;
    max-width: 50px;
    padding: 2px 4px;
    font-size: 12px;
}

.disabled {
    color: #d1d5db;
}

.summary {
    background: white;
    padding: 20px;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
    margin-bottom: 20px;
}

.summary p {
    margin: 5px 0;
}

.grand-total {
    font-size: 1.2em;
    color: #2563eb;
    margin-top: 10px !important;
}

.note {
    font-size: 0.85em;
    color: #6b7280;
    margin: 2px 0 8px 0 !important;
    font-style: italic;
}

.tree {
    margin: 20px 0;
}

.tree-node {
    background: white;
    padding: 10px;
    border-radius: 4px;
    margin: 5px 0;
    border-left: 3px solid #2563eb;
}

.node-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
}

.complexity {
    font-size: 13px;
    color: #2563eb;
    font-weight: 600;
}

.interface-info {
    font-size: 12px;
    color: #6b7280;
    margin: 2px 0;
}

.results-table {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 6px;
    overflow: hidden;
    margin: 15px 0;
}

.results-table th,
.results-table td {
    border: 1px solid #e5e7eb;
    padding: 8px;
    text-align: left;
    font-size: 13px;
}

.results-table th {
    background: #f8fafc;
    font-weight: 600;
}

.flash {
    background: #fef3c7;
    border: 1px solid #fbbf24;
    padding: 10px;
    border-radius: 4px;
    margin-bottom: 15px;
}

.button {
    display: inline-block;
    padding: 10px 20px;
    background: #2563eb;
    color: white;
    text-decoration: none;
    border-radius: 4px;
    margin-top: 15px;
}

.button:hover {
    background: #1d4ed8;
}

.nav-buttons {
    display: flex;
    gap: 10px;
    margin: 20px 0;
}

.hint {
    font-size: 12px;
    color: #6b7280;
    margin-left: 10px;
}

.delete-btn {
    background: #dc2626;
    padding: 4px 8px;
    font-size: 11px;
}

.delete-btn:hover {
    background: #b91c1c;
}

.save-status {
    margin-left: 10px;
    font-size: 13px;
    color: #059669;
}

.coupling-selector {
    display: flex;
    gap: 20px;
    margin-bottom: 20px;
}

.coupling-selector .form-group {
    flex: 1;
    max-width: 400px;
}

.coupling-selector select {
    width: 100%;
}

.graph-controls {
    display: flex;
    gap: 10px;
    margin-bottom: 15px;
}

.graph-container {
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
    overflow: auto;
    max-height: 700px;
}

#system-graph {
    display: block;
}

.component-node {
    cursor: pointer;
}

.component-node:hover rect {
    filter: brightness(0.95);
}

.cloud-box {
    cursor: pointer;
}

.cloud-box:hover path {
    filter: brightness(0.95);
}

.graph-legend {
    margin-top: 20px;
    padding: 15px;
    background: white;
    border: 1px solid #e5e7eb;
    border-radius: 6px;
}

.graph-legend h3 {
    margin-bottom: 10px;
    color: #475569;
}

.legend-item {
    display: inline-block;
    margin-right: 20px;
    margin-bottom: 5px;
    font-size: 13px;
    color: #475569;
}

.legend-color {
    display: inline-block;
    width: 16px;
    height: 16px;
    vertical-align: middle;
    margin-right: 5px;
    border-radius: 3px;
}

.legend-line {
    display: inline-block;
    width: 30px;
    height: 2px;
    background: #475569;
    vertical-align: middle;
    margin-right: 5px;
}

.legend-inbound {
    display: inline-block;
    width: 12px;
    height: 12px;
    background: #059669;
    border-radius: 50%;
    vertical-align: middle;
    margin-right: 5px;
}

.legend-outbound {
    display: inline-block;
    width: 12px;
    height: 12px;
    background: #dc2626;
    border-radius: 50%;
    vertical-align: middle;
    margin-right: 5px;
}

.tree-node.depth-0 { border-left-color: #2563eb; }
.tree-node.depth-1 { border-left-color: #4f46e5; margin-left: 20px; }
.tree-node.depth-2 { border-left-color: #7c3aed; margin-left: 40px; }
.tree-node.depth-3 { border-left-color: #9333ea; margin-left: 60px; }
.tree-node.depth-4 { border-left-color: #a855f7; margin-left: 80px; }
.tree-node.depth-5 { border-left-color: #d946ef; margin-left: 100px; }

.element-list {
    display: flex;
    flex-wrap: wrap;
    gap: 8px;
    margin: 5px 0;
}

.element-info {
    display: inline-flex;
    align-items: center;
    gap: 4px;
    padding: 2px 8px;
    border-radius: 3px;
    font-size: 11px;
}

.element-info.inbound {
    background: #d1fae5;
    color: #065f46;
}

.element-info.outbound {
    background: #fee2e2;
    color: #991b1b;
}

.elem-dir {
    font-weight: bold;
}

.complexity.upper {
    color: #9333ea;
    margin-left: 10px;
}

.summary-grid {
    display: grid;
    grid-template-columns: 1fr 1fr;
    gap: 20px;
}

.summary-card {
    padding: 15px;
    background: #f8fafc;
    border-radius: 6px;
    border: 1px solid #e5e7eb;
}

.summary-card h3 {
    margin-bottom: 10px;
    color: #475569;
}

.formula {
    margin: 8px 0;
    padding: 8px 10px;
    background: white;
    border-radius: 4px;
    border: 1px solid #e5e7eb;
}

.formula p {
    margin: 2px 0;
    font-size: 13px;
}

.formula-expr {
    font-family: 'Courier New', Courier, monospace;
    font-size: 13px;
    color: #1e40af;
    background: #eff6ff;
    padding: 4px 8px;
    border-radius: 3px;
    display: inline-block;
    margin: 4px 0;
}

.reference {
    font-size: 12px;
    color: #6b7280;
    font-style: italic;
    margin-bottom: 15px;
}

.flash.error {
    background: #fee2e2;
    border-color: #fca5a5;
    color: #991b1b;
}

.flash.success {
    background: #d1fae5;
    border-color: #6ee7b7;
    color: #065f46;
}

/* Spreadsheet table */
.spreadsheet {
    width: 100%;
    border-collapse: collapse;
    background: white;
    border-radius: 6px;
    overflow: hidden;
    margin: 15px 0;
}

.spreadsheet th,
.spreadsheet td {
    border: 1px solid #e5e7eb;
    padding: 6px 8px;
    font-size: 13px;
}

.spreadsheet th {
    background: #f1f5f9;
    font-weight: 600;
    color: #475569;
    text-align: left;
    position: sticky;
    top: 0;
}

.spreadsheet td input[type="text"],
.spreadsheet td input[type="number"] {
    border: none;
    background: transparent;
    width: 100%;
    padding: 4px;
    font-size: 13px;
    max-width: none;
}

.spreadsheet td input:focus {
    outline: 2px solid #2563eb;
    border-radius: 2px;
    background: #eff6ff;
}

.spreadsheet td select {
    border: none;
    background: transparent;
    width: 100%;
    padding: 4px;
    font-size: 13px;
    max-width: none;
}

.spreadsheet td select:focus {
    outline: 2px solid #2563eb;
    border-radius: 2px;
}

.spreadsheet tr:hover {
    background: #f8fafc;
}

.spreadsheet .row-num {
    color: #9ca3af;
    font-size: 11px;
    text-align: center;
    width: 30px;
}

.spreadsheet .computed {
    color: #2563eb;
    font-weight: 600;
    font-size: 12px;
}

.spreadsheet .row-delete {
    background: none;
    border: none;
    color: #dc2626;
    cursor: pointer;
    font-size: 16px;
    padding: 2px 6px;
    margin: 0;
}

.spreadsheet .row-delete:hover {
    background: #fee2e2;
    border-radius: 3px;
}

.add-row-bar {
    padding: 10px;
    background: #f8fafc;
    border: 1px solid #e5e7eb;
    border-top: none;
    border-radius: 0 0 6px 6px;
    margin-top: -1px;
}

.add-row-bar button {
    background: #059669;
    color: white;
    border: none;
    padding: 6px 14px;
    border-radius: 4px;
    cursor: pointer;
    font-size: 13px;
    margin: 0;
}

.add-row-bar button:hover {
    background: #047857;
}

.save-bar {
    display: flex;
    justify-content: space-between;
    align-items: center;
    padding: 15px 0;
    margin-top: 10px;
    border-top: 2px solid #e5e7eb;
}

.save-bar .button {
    margin: 0;
}

.invalid-cell {
    background: #fee2e2 !important;
    outline: 1px solid #fca5a5;
}

.section-header {
    display: flex;
    justify-content: space-between;
    align-items: center;
    margin-bottom: 5px;
}

.section-header h2 {
    margin: 0;
}

.nav-brand {
    font-weight: 700;
    font-size: 18px;
    color: #1e293b !important;
    display: flex;
    flex-direction: column;
    line-height: 1.2;
}

.nav-subtitle {
    font-size: 10px;
    font-weight: 400;
    color: #6b7280;
    margin-top: 1px;
}

.nav-divider {
    color: #d1d5db;
}

.nav-user {
    color: #6b7280;
    font-size: 13px;
    margin-left: auto;
    padding: 0 0.5rem;
}

.flash.info {
    background: #dbeafe;
    border-color: #93c5fd;
    color: #1e40af;
}

.btn {
    display: inline-block;
    padding: 8px 16px;
    background: #2563eb;
    color: white;
    text-decoration: none;
    border: none;
    border-radius: 4px;
    cursor: pointer;
    font-size: 14px;
    font-weight: 500;
    text-align: center;
}

.btn:hover {
    background: #1d4ed8;
    text-decoration: none;
}

.btn-primary {
    background: #2563eb;
}

.btn-danger {
    background: #dc2626;
}

.btn-danger:hover {
    background: #b91c1c;
}

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

.muted {
    color: #6b7280;
}

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

.legend {
    margin-top: 2rem;
    padding: 1rem 1.25rem;
    background: #f8fafc;
    border: 1px solid #e2e8f0;
    border-radius: 6px;
    font-size: 0.9rem;
    color: #475569;
}

.legend h3 {
    margin: 0 0 0.75rem 0;
    font-size: 1rem;
    color: #1e293b;
}

.legend dl {
    margin: 0;
    display: grid;
    grid-template-columns: auto 1fr;
    gap: 0.4rem 1rem;
}

.legend dt {
    font-weight: 600;
    color: #1e293b;
}

.legend dd {
    margin: 0;
}

footer {
    text-align: center;
    padding: 1.5rem 1rem;
    margin-top: 3rem;
    border-top: 1px solid #e2e8f0;
    font-size: 0.8rem;
    color: #94a3b8;
}

.paper-notice {
    background: #fef2f2;
    border-left: 4px solid #dc2626;
    padding: 0.6rem 1rem;
    margin-bottom: 1.5rem;
    font-size: 0.85rem;
    color: #991b1b;
}

.paper-notice a {
    color: #991b1b;
    font-weight: 600;
    text-decoration: underline;
}

.coupling-badge {
    display: inline-block;
    padding: 2px 8px;
    border-radius: 12px;
    font-size: 0.75rem;
    font-weight: 600;
    text-transform: lowercase;
}

.coupling-external {
    background: #fef3c7;
    color: #92400e;
    border: 1px solid #fcd34d;
}

.coupling-internal {
    background: #e0e7ff;
    color: #3730a3;
    border: 1px solid #a5b4fc;
}
